Revert "home: Don't use pointer to compute furthest_read_time."

This reverts commit 8f32db81a1.

This change unfortunately requires an index that we don't have, and
thus is incredibly expensive.  We'll need to do a thoughtful reworking
before we can integrate it again.
This commit is contained in:
Tim Abbott 2020-04-27 22:29:08 -07:00
parent 1094589f79
commit 976e554799
3 changed files with 9 additions and 20 deletions

View File

@ -1962,10 +1962,6 @@ def get_usermessage_by_message_id(user_profile: UserProfile, message_id: int) ->
except UserMessage.DoesNotExist: except UserMessage.DoesNotExist:
return None return None
def get_latest_read_usermessage(user_profile: UserProfile) -> Optional[UserMessage]:
return UserMessage.objects.select_related().filter(user_profile=user_profile,
flags=UserMessage.flags.read).last()
class ArchivedUserMessage(AbstractUserMessage): class ArchivedUserMessage(AbstractUserMessage):
"""Used as a temporary holding place for deleted UserMessages objects """Used as a temporary holding place for deleted UserMessages objects
before they are permanently deleted. This is an important part of before they are permanently deleted. This is an important part of

View File

@ -22,7 +22,7 @@ from zerver.lib.users import compute_show_invites_and_add_streams
from zerver.models import ( from zerver.models import (
get_realm, get_stream, get_user, UserProfile, get_realm, get_stream, get_user, UserProfile,
flush_per_request_caches, DefaultStream, Realm, flush_per_request_caches, DefaultStream, Realm,
get_system_bot, UserMessage get_system_bot,
) )
from zerver.views.home import sent_time_in_epoch_seconds, compute_navbar_logo_url from zerver.views.home import sent_time_in_epoch_seconds, compute_navbar_logo_url
from corporate.models import Customer, CustomerPlan from corporate.models import Customer, CustomerPlan
@ -458,19 +458,9 @@ class HomeTest(ZulipTestCase):
user_profile.save() user_profile.save()
self.login_user(user_profile) self.login_user(user_profile)
result = self._get_home_page() with patch('logging.warning') as mock:
self._sanity_check(result) result = self._get_home_page()
mock.assert_called_once_with('User %s has invalid pointer 999999' % (user_profile.id,))
def test_no_read_user_messages(self) -> None:
user_profile = self.example_user('hamlet')
user_profile.pointer = 1
user_profile.save()
# Mark all messages as unread
UserMessage.objects.filter(user_profile=user_profile).update(flags=~UserMessage.flags.read)
self.login_user(user_profile)
result = self._get_home_page()
self._sanity_check(result) self._sanity_check(result)
def test_topic_narrow(self) -> None: def test_topic_narrow(self) -> None:

View File

@ -13,7 +13,7 @@ from zerver.forms import ToSForm
from zerver.models import Message, Stream, UserProfile, \ from zerver.models import Message, Stream, UserProfile, \
Realm, UserMessage, \ Realm, UserMessage, \
PreregistrationUser, \ PreregistrationUser, \
get_latest_read_usermessage get_usermessage_by_message_id
from zerver.lib.events import do_events_register from zerver.lib.events import do_events_register
from zerver.lib.actions import do_change_tos_version, \ from zerver.lib.actions import do_change_tos_version, \
realm_user_count realm_user_count
@ -223,7 +223,10 @@ def home_real(request: HttpRequest) -> HttpResponse:
register_ret['pointer'] = register_ret['max_message_id'] register_ret['pointer'] = register_ret['max_message_id']
furthest_read_time = None furthest_read_time = None
else: else:
latest_read = get_latest_read_usermessage(user_profile) latest_read = get_usermessage_by_message_id(user_profile, user_profile.pointer)
if latest_read is None:
# Don't completely fail if your saved pointer ID is invalid
logging.warning("User %s has invalid pointer %s" % (user_profile.id, user_profile.pointer))
furthest_read_time = sent_time_in_epoch_seconds(latest_read) furthest_read_time = sent_time_in_epoch_seconds(latest_read)
# We pick a language for the user as follows: # We pick a language for the user as follows: