mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-25 14:50:29 +00:00
remove sdoc notification count cache
This commit is contained in:
@@ -13,7 +13,6 @@ from seahub.api2.authentication import TokenAuthentication
|
||||
from seahub.api2.throttling import UserRateThrottle
|
||||
from seahub.notifications.models import UserNotification
|
||||
|
||||
from seahub.seadoc.models import get_cache_key_of_unseen_sdoc_notifications
|
||||
from seahub.notifications.models import get_cache_key_of_unseen_notifications
|
||||
from seahub.notifications.utils import update_notice_detail, update_sdoc_notice_detail
|
||||
from seahub.api2.utils import api_error
|
||||
@@ -209,16 +208,9 @@ class SdocNotificationsView(APIView):
|
||||
notice['seen'] = i.seen
|
||||
|
||||
notification_list.append(notice)
|
||||
cache_key = get_cache_key_of_unseen_sdoc_notifications(username)
|
||||
unseen_count_from_cache = cache.get(cache_key, None)
|
||||
|
||||
# for case of count value is `0`
|
||||
if unseen_count_from_cache is not None:
|
||||
result['unseen_count'] = unseen_count_from_cache
|
||||
else:
|
||||
unseen_count = SeadocNotification.objects.filter(username=username, seen=False).count()
|
||||
result['unseen_count'] = unseen_count
|
||||
cache.set(cache_key, unseen_count)
|
||||
unseen_count = SeadocNotification.objects.filter(username=username, seen=False).count()
|
||||
result['unseen_count'] = unseen_count
|
||||
|
||||
total_count = SeadocNotification.objects.filter(username=username).count()
|
||||
|
||||
@@ -237,9 +229,6 @@ class SdocNotificationsView(APIView):
|
||||
error_msg = 'Internal Server Error'
|
||||
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
|
||||
|
||||
cache_key = get_cache_key_of_unseen_sdoc_notifications(username)
|
||||
cache.delete(cache_key)
|
||||
|
||||
return Response({'success': True})
|
||||
|
||||
def delete(self, request):
|
||||
@@ -252,9 +241,6 @@ class SdocNotificationsView(APIView):
|
||||
|
||||
SeadocNotification.objects.remove_user_notifications(username)
|
||||
|
||||
cache_key = get_cache_key_of_unseen_sdoc_notifications(username)
|
||||
cache.delete(cache_key)
|
||||
|
||||
return Response({'success': True})
|
||||
|
||||
|
||||
@@ -300,9 +286,6 @@ class SdocNotificationView(APIView):
|
||||
notice.seen = True
|
||||
notice.save()
|
||||
|
||||
cache_key = get_cache_key_of_unseen_sdoc_notifications(username)
|
||||
cache.delete(cache_key)
|
||||
|
||||
return Response({'success': True})
|
||||
|
||||
|
||||
@@ -373,9 +356,6 @@ class AllNotificationsView(APIView):
|
||||
cache_key = get_cache_key_of_unseen_notifications(username)
|
||||
unseen_count_from_cache = cache.get(cache_key, None)
|
||||
|
||||
sdoc_cache_key = get_cache_key_of_unseen_sdoc_notifications(username)
|
||||
sdoc_unseen_count_from_cache = cache.get(sdoc_cache_key, None)
|
||||
|
||||
# for case of count value is `0`
|
||||
if unseen_count_from_cache is not None:
|
||||
result['general']['unseen_count'] = unseen_count_from_cache
|
||||
@@ -384,12 +364,8 @@ class AllNotificationsView(APIView):
|
||||
result['general']['unseen_count'] = unseen_count
|
||||
cache.set(cache_key, unseen_count)
|
||||
|
||||
if sdoc_unseen_count_from_cache is not None:
|
||||
result['discussion']['unseen_count'] = sdoc_unseen_count_from_cache
|
||||
else:
|
||||
sdoc_unseen_count = SeadocNotification.objects.filter(username=username, seen=False).count()
|
||||
result['discussion']['unseen_count'] = sdoc_unseen_count
|
||||
cache.set(sdoc_cache_key, sdoc_unseen_count)
|
||||
sdoc_unseen_count = SeadocNotification.objects.filter(username=username, seen=False).count()
|
||||
result['discussion']['unseen_count'] = sdoc_unseen_count
|
||||
|
||||
total_count = UserNotification.objects.filter(to_user=username).count()
|
||||
sdoc_total_count = SeadocNotification.objects.filter(username=username).count()
|
||||
@@ -419,8 +395,6 @@ class AllNotificationsView(APIView):
|
||||
return api_error(status.HTTP_500_INTERNAL_SERVER_ERROR, error_msg)
|
||||
|
||||
cache_key = get_cache_key_of_unseen_notifications(username)
|
||||
sdoc_cache_key = get_cache_key_of_unseen_sdoc_notifications(username)
|
||||
cache.delete(cache_key)
|
||||
cache.delete(sdoc_cache_key)
|
||||
|
||||
return Response({'success': True})
|
||||
|
@@ -29,7 +29,6 @@ from django.core.files.uploadhandler import TemporaryFileUploadHandler
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.views.decorators.cache import cache_page
|
||||
from django.views.decorators.http import condition
|
||||
from django.core.cache import cache
|
||||
|
||||
from seaserv import seafile_api, check_quota, get_org_id_by_repo_id, ccnet_api
|
||||
|
||||
@@ -55,7 +54,7 @@ from seahub.utils import get_file_type_and_ext, normalize_file_path, \
|
||||
from seahub.tags.models import FileUUIDMap
|
||||
from seahub.utils.error_msg import file_type_error_msg
|
||||
from seahub.utils.repo import parse_repo_perm, get_related_users_by_repo
|
||||
from seahub.seadoc.models import SeadocHistoryName, SeadocRevision, SeadocCommentReply, SeadocNotification, get_cache_key_of_unseen_sdoc_notifications
|
||||
from seahub.seadoc.models import SeadocHistoryName, SeadocRevision, SeadocCommentReply, SeadocNotification
|
||||
from seahub.avatar.templatetags.avatar_tags import api_avatar_url
|
||||
from seahub.base.templatetags.seahub_tags import email2nickname, \
|
||||
email2contact_email
|
||||
@@ -1145,9 +1144,6 @@ class SeadocCommentsView(APIView):
|
||||
))
|
||||
try:
|
||||
SeadocNotification.objects.bulk_create(new_notifications)
|
||||
# delete sdoc notification count cache
|
||||
sdoc_cache_key = get_cache_key_of_unseen_sdoc_notifications(username)
|
||||
cache.delete(sdoc_cache_key)
|
||||
except Exception as e:
|
||||
logger.error(e)
|
||||
error_msg = 'Internal Server Error'
|
||||
@@ -1372,8 +1368,6 @@ class SeadocCommentRepliesView(APIView):
|
||||
))
|
||||
try:
|
||||
SeadocNotification.objects.bulk_create(new_notifications)
|
||||
sdoc_cache_key = get_cache_key_of_unseen_sdoc_notifications(username)
|
||||
cache.delete(sdoc_cache_key)
|
||||
except Exception as e:
|
||||
logger.error(e)
|
||||
error_msg = 'Internal Server Error'
|
||||
|
@@ -7,7 +7,6 @@ from django.db import models
|
||||
from seahub.utils.timeutils import datetime_to_isoformat_timestr
|
||||
from seahub.base.templatetags.seahub_tags import email2nickname
|
||||
from seahub.seadoc.settings import SDOC_REVISIONS_DIR
|
||||
from seahub.utils import normalize_cache_key
|
||||
|
||||
class SeadocHistoryNameManager(models.Manager):
|
||||
def update_name(self, doc_uuid, obj_id, name):
|
||||
@@ -251,11 +250,6 @@ class SeadocCommentReply(models.Model):
|
||||
### sdoc notification
|
||||
MSG_TYPE_REPLY = 'reply'
|
||||
MSG_TYPE_COMMENT = 'comment'
|
||||
SDOC_NOTIFICATION_COUNT_CACHE_PREFIX = 'SDOC_NOTIFICATION_COUNT_'
|
||||
|
||||
def get_cache_key_of_unseen_sdoc_notifications(username):
|
||||
return normalize_cache_key(username,
|
||||
SDOC_NOTIFICATION_COUNT_CACHE_PREFIX)
|
||||
|
||||
class SeadocNotificationManager(models.Manager):
|
||||
def total_count(self, doc_uuid, username):
|
||||
|
Reference in New Issue
Block a user