From 00e5f904a3c8f10bcc13cab3ac8ac69bc4a47733 Mon Sep 17 00:00:00 2001 From: Zev Benjamin Date: Thu, 28 Mar 2013 13:09:27 -0400 Subject: [PATCH] Use do_events_register() in home() and pass the results to the initial page load (imported from commit 532036c01bde1f5d49c43a96ce6aa496ca77cea9) --- zephyr/static/js/zephyr.js | 16 +++++++--------- zephyr/views.py | 18 +++++++++--------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/zephyr/static/js/zephyr.js b/zephyr/static/js/zephyr.js index 60e0874d10..d3d24b45db 100644 --- a/zephyr/static/js/zephyr.js +++ b/zephyr/static/js/zephyr.js @@ -11,8 +11,7 @@ var queued_flag_timer; var viewport = $(window); var get_updates_params = { - pointer: -1, - last_event_id: 0 + pointer: -1 }; var get_updates_failures = 0; @@ -604,7 +603,10 @@ function get_updates(options) { get_updates_params.pointer = furthest_read; get_updates_params.dont_block = options.dont_block || get_updates_failures > 0; - get_updates_params.queue_id = page_params.event_queue_id; + if (get_updates_params.queue_id === undefined) { + get_updates_params.queue_id = page_params.event_queue_id; + get_updates_params.last_event_id = page_params.last_event_id; + } get_updates_xhr = $.ajax({ type: 'POST', @@ -628,12 +630,8 @@ function get_updates(options) { var new_pointer; $.each(data.events, function (idx, event) { - if (get_updates_params.last_event_id === undefined) { - get_updates_params.last_event_id = event.id; - } else { - get_updates_params.last_event_id = Math.max(get_updates_params.last_event_id, - event.id); - } + get_updates_params.last_event_id = Math.max(get_updates_params.last_event_id, + event.id); switch (event.type) { case 'message': diff --git a/zephyr/views.py b/zephyr/views.py index 879aba64bd..9465affd1f 100644 --- a/zephyr/views.py +++ b/zephyr/views.py @@ -399,13 +399,14 @@ def home(request): user_profile = get_user_profile_by_user_id(request.user.id) - num_messages = UserMessage.objects.filter(user_profile=user_profile).count() + register_ret = do_events_register(user_profile, apply_markdown=True) + user_has_messages = (register_ret['max_message_id'] != -1) # Brand new users get the tutorial. # Compute this here, before we set user_profile.pointer below. needs_tutorial = settings.TUTORIAL_ENABLED and user_profile.pointer == -1 - if user_profile.pointer == -1 and num_messages > 0: + if user_profile.pointer == -1 and user_has_messages: # Put the new user's pointer at the bottom # # This improves performance, because we limit backfilling of messages @@ -413,10 +414,7 @@ def home(request): # organization is interested in recent messages more than the very # first messages on the system. - max_id = (UserMessage.objects.filter(user_profile=user_profile) - .order_by('message') - .reverse()[0]).message_id - user_profile.pointer = max_id + user_profile.pointer = register_ret['max_message_id'] user_profile.last_pointer_updater = request.session.session_key # Populate personals autocomplete list based on everyone in your @@ -434,10 +432,10 @@ def home(request): page_params = simplejson.encoder.JSONEncoderForHTML().encode(dict( debug_mode = settings.DEBUG, poll_timeout = settings.POLL_TIMEOUT, - have_initial_messages = num_messages > 0, + have_initial_messages = user_has_messages, stream_list = gather_subscriptions(user_profile), people_list = people, - initial_pointer = user_profile.pointer, + initial_pointer = register_ret['pointer'], fullname = user_profile.full_name, email = user_profile.user.email, domain = user_profile.realm.domain, @@ -445,7 +443,9 @@ def home(request): needs_tutorial = needs_tutorial, desktop_notifications_enabled = user_profile.enable_desktop_notifications, - event_queue_id = request_event_queue(user_profile, True) + event_queue_id = register_ret['queue_id'], + last_event_id = register_ret['last_event_id'], + max_message_id = register_ret['max_message_id'] )) try: