diff --git a/seahub/api2/endpoints/notifications.py b/seahub/api2/endpoints/notifications.py index e852dbc1b3..c411623b75 100644 --- a/seahub/api2/endpoints/notifications.py +++ b/seahub/api2/endpoints/notifications.py @@ -344,7 +344,7 @@ class AllNotificationsView(APIView): sdoc_notice_list = SeadocNotification.objects.list_all_by_user(username)[start:end] general_result_notices = update_notice_detail(request, general_notice_list) - sdoc_result_notices = update_sdoc_notice_detail(request, sdoc_notice_list) + sdoc_result_notices = update_sdoc_notice_detail(sdoc_notice_list) notification_list = [] sdoc_notification_list = [] diff --git a/seahub/notifications/utils.py b/seahub/notifications/utils.py index 1189d3db8c..8863ef299d 100644 --- a/seahub/notifications/utils.py +++ b/seahub/notifications/utils.py @@ -404,27 +404,29 @@ def update_notice_detail(request, notices): return notices -def update_sdoc_notice_detail(request, notices): +def update_sdoc_notice_detail(notices): doc_uuid_set = set() for notice in notices: doc_uuid_set.add(notice.doc_uuid) - doc_uuid_map = {} + uuid_doc_map = {} uuids = FileUUIDMap.objects.get_fileuuidmap_in_uuids(doc_uuid_set) for uuid in uuids: - if uuid not in doc_uuid_map: + if uuid not in uuid_doc_map: origin_file_path = posixpath.join(uuid.parent_path, uuid.filename) - doc_uuid_map[str(uuid.uuid)] = (origin_file_path, uuid.filename, uuid.repo_id) + uuid_doc_map[str(uuid.uuid)] = (origin_file_path, uuid.filename, uuid.repo_id) for notice in notices: - uuid = doc_uuid_map[notice.doc_uuid] + doc = uuid_doc_map.get(notice.doc_uuid) or None + if not doc: + continue if notice.is_comment(): try: d = json.loads(notice.detail) url, _, _ = api_avatar_url(d['author']) d['avatar_url'] = url - d['sdoc_path'] = uuid[0] - d['sdoc_name'] = uuid[1] - d['repo_id'] = uuid[2] + d['sdoc_path'] = doc[0] + d['sdoc_name'] = doc[1] + d['repo_id'] = doc[2] notice.detail = d except Exception as e: logger.error(e) @@ -433,9 +435,9 @@ def update_sdoc_notice_detail(request, notices): d = json.loads(notice.detail) url, _, _ = api_avatar_url(d['author']) d['avatar_url'] = url - d['sdoc_path'] = uuid[0] - d['sdoc_name'] = uuid[1] - d['repo_id'] = uuid[2] + d['sdoc_path'] = doc[0] + d['sdoc_name'] = doc[1] + d['repo_id'] = doc[2] notice.detail = d except Exception as e: logger.error(e) diff --git a/seahub/tags/models.py b/seahub/tags/models.py index 262100ba72..b42ec66436 100644 --- a/seahub/tags/models.py +++ b/seahub/tags/models.py @@ -23,10 +23,8 @@ class FileUUIDMapManager(models.Manager): return None def get_fileuuidmap_in_uuids(self, uuids): - try: - return super(FileUUIDMapManager, self).filter(uuid__in=uuids) - except self.model.DoesNotExist: - return None + return super(FileUUIDMapManager, self).filter(uuid__in=uuids) + def get_or_create_fileuuidmap(self, repo_id, parent_path, filename, is_dir): """ create filemap by repo_id、 parent_path、filename、id_dir