Add caching for user basic info

This commit is contained in:
cuom1999 2023-10-10 19:37:36 -05:00
parent 7f854c40dd
commit ed287b6ff3
15 changed files with 110 additions and 33 deletions

View file

@ -8,6 +8,8 @@ from django.db.models.functions import Coalesce
from chat_box.models import Ignore, Message, UserRoom, Room
from judge.caching import cache_wrapper
secret_key = settings.CHAT_SECRET_KEY
fernet = Fernet(secret_key)
@ -37,6 +39,7 @@ def encrypt_channel(channel):
)
@cache_wrapper(prefix="gub")
def get_unread_boxes(profile):
ignored_rooms = Ignore.get_ignored_rooms(profile)
unread_boxes = (

View file

@ -36,7 +36,7 @@ from judge.jinja2.gravatar import gravatar
from judge.models import Friend
from chat_box.models import Message, Profile, Room, UserRoom, Ignore
from chat_box.utils import encrypt_url, decrypt_url, encrypt_channel
from chat_box.utils import encrypt_url, decrypt_url, encrypt_channel, get_unread_boxes
import json
@ -208,6 +208,7 @@ def post_message(request):
)
else:
Room.last_message_body.dirty(room)
for user in room.users():
event.post(
encrypt_channel("chat_" + str(user.id)),
@ -223,6 +224,7 @@ def post_message(request):
UserRoom.objects.filter(user=user, room=room).update(
unread_count=F("unread_count") + 1
)
get_unread_boxes.dirty(user)
return JsonResponse(ret)
@ -285,6 +287,8 @@ def update_last_seen(request, **kwargs):
user_room.unread_count = 0
user_room.save()
get_unread_boxes.dirty(profile)
return JsonResponse({"msg": "updated"})