From 9807cbd752016de12a52cb8c1937b42d049d7730 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E6=B0=B8=E5=BC=BA?= <11704063+s-yongqiang@user.noreply.gitee.com> Date: Tue, 3 Dec 2024 10:57:42 +0800 Subject: [PATCH] remove sdoc notification count cache --- seahub/api2/endpoints/notifications.py | 36 ++++---------------------- seahub/seadoc/apis.py | 8 +----- seahub/seadoc/models.py | 6 ----- 3 files changed, 6 insertions(+), 44 deletions(-) diff --git a/seahub/api2/endpoints/notifications.py b/seahub/api2/endpoints/notifications.py index 28e929a14d..51f9229871 100644 --- a/seahub/api2/endpoints/notifications.py +++ b/seahub/api2/endpoints/notifications.py @@ -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,17 +208,10 @@ 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() result['notification_list'] = notification_list @@ -236,9 +228,6 @@ class SdocNotificationsView(APIView): logger.error(e) 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}) @@ -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}) diff --git a/seahub/seadoc/apis.py b/seahub/seadoc/apis.py index 0fc785f2f1..6d1b73753d 100644 --- a/seahub/seadoc/apis.py +++ b/seahub/seadoc/apis.py @@ -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' diff --git a/seahub/seadoc/models.py b/seahub/seadoc/models.py index 9a304b4ec8..f674aa589e 100644 --- a/seahub/seadoc/models.py +++ b/seahub/seadoc/models.py @@ -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):