Skip to content

Commit

Permalink
roled back 8a6d2e8 (origin/bug/MUWM-5324)
Browse files Browse the repository at this point in the history
  • Loading branch information
fanglinfang committed Jan 4, 2024
1 parent e3d9615 commit 6a4f954
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions myuw/dao/notice.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,34 @@ def _get_user_notices(request, notices):
notice_dict[notice_hash] = notice

# Set read status for notices already in db
for user_notice in UserNotices.objects.filter(
user=user, notice_hash__in=notice_dict.keys()):
keys = notice_dict.keys()
user_notices = UserNotices.objects.filter(user=user,
notice_hash__in=keys)
for user_notice in user_notices:
matched_notice = notice_dict[user_notice.notice_hash]
matched_notice.is_read = user_notice.is_read
notices_with_read_status.append(matched_notice)
del notice_dict[user_notice.notice_hash]

# Create UserNotices for new notices
user_notices_to_create = []
for notice in notice_dict.values():
user_notice, _ = UserNotices.objects.get_or_create(
notice_hash=notice.id_hash, user=user, defaults={
'notice_cattype': notice.notice_category + notice.notice_type})
notice.is_read = user_notice.is_read
notices_with_read_status.append(notice)

user_notice = UserNotices()
user_notice.notice_hash = notice.id_hash
user_notice.user = user
cattype = notice.notice_category + notice.notice_type
user_notice.notice_cattype = cattype

user_notices_to_create.append(user_notice)

try:
UserNotices.objects.bulk_create(user_notices_to_create)
except IntegrityError:
# MUWM-2016. This should be rare - 2 processes running at just about
# exactly the same time. In that case especially, the bulk create list
# should be the same. And if it isn't, big deal?
pass

# Add newly created UserNotices into returned list
notices_with_read_status.extend(list(notice_dict.values()))
return notices_with_read_status

0 comments on commit 6a4f954

Please sign in to comment.