Add lower message id bound when marking messages as read for the mobile unread count hack

Having a message ID range significantly improves the query
performance because the number of messages Postgres has to consider
is much smaller.

(imported from commit 9b007457712f1c1502d526abea1b6fd742bd911d)
This commit is contained in:
Zev Benjamin 2013-04-24 10:47:01 -04:00
parent 102988e430
commit 75bbda1dad

View File

@ -521,6 +521,7 @@ def update_pointer_backend(request, user_profile,
if pointer <= user_profile.pointer:
return json_success()
prev_pointer = user_profile.pointer
user_profile.pointer = pointer
user_profile.save(update_fields=["pointer"])
@ -530,6 +531,7 @@ def update_pointer_backend(request, user_profile,
# this is a shim that will mark as read any messages up until the
# pointer move
UserMessage.objects.filter(user_profile=user_profile,
message__id__gt=prev_pointer,
message__id__lte=pointer,
flags=~UserMessage.flags.read) \
.update(flags=F('flags').bitor(UserMessage.flags.read))