From f817bf61447a54b1a8a0660e521e6050e0c41ca5 Mon Sep 17 00:00:00 2001 From: Zev Benjamin Date: Mon, 22 Oct 2012 17:06:22 -0400 Subject: [PATCH] Pass the session that updated the pointer from Django to Tornado This allows us to check whether the session that updated the pointer is the same as a session that is doing a long poll to avoid sending new pointer information when that information is coming from the same session. We still return from the long poll early, though, which is sub-optimal. (imported from commit 7d4be0956f112eacefb7d198ea929957cd2b05e3) --- zephyr/models.py | 5 +++-- zephyr/views.py | 11 +++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/zephyr/models.py b/zephyr/models.py index 09a13b6efd..5aa5ef24d5 100644 --- a/zephyr/models.py +++ b/zephyr/models.py @@ -126,11 +126,12 @@ class UserProfile(models.Model): callbacks_table.clear(self.user.id, Callbacks.TYPE_RECEIVE) - def update_pointer(self, new_pointer): + def update_pointer(self, new_pointer, updater_session): global callbacks_table for cb in callbacks_table.get(self.user.id, Callbacks.TYPE_POINTER_UPDATE): - cb(new_pointer=new_pointer) + cb(new_pointer=new_pointer, updater_session=updater_session, + user_profile=self) callbacks_table.clear(self.user.id, Callbacks.TYPE_POINTER_UPDATE) diff --git a/zephyr/views.py b/zephyr/views.py index 9a84c2f3c1..c4baeea385 100644 --- a/zephyr/views.py +++ b/zephyr/views.py @@ -231,13 +231,15 @@ def update_pointer_backend(request, user_profile): requests.post(settings.NOTIFY_POINTER_UPDATE_URL, data=[ ('secret', settings.SHARED_SECRET), ('user', user_profile.user.id), - ('new_pointer', pointer)]) + ('new_pointer', pointer), + ('updater_session', request.session.session_key)]) return json_success() def format_updates_response(messages=[], mit_sync_bot=False, apply_markdown=False, reason_empty=None, user_profile=None, - new_pointer=None, where='bottom'): + new_pointer=None, where='bottom', + updater_session=''): max_message_id = None if user_profile is not None: try: @@ -256,7 +258,7 @@ def format_updates_response(messages=[], mit_sync_bot=False, apply_markdown=Fals if max_message_id is not None: # TODO: Figure out how to accurately return this always ret["max_message_id"] = max_message_id - if new_pointer is not None: + if new_pointer is not None and updater_session != user_profile.last_pointer_updater: ret['new_pointer'] = new_pointer return ret @@ -609,8 +611,9 @@ def notify_pointer_update(request, handler): # FIXME: better query user_profile = UserProfile.objects.get(id=request.POST['user']) new_pointer = int(request.POST['new_pointer']) + updater_session = request.POST['updater_session'] - user_profile.update_pointer(new_pointer) + user_profile.update_pointer(new_pointer, updater_session) handler.finish()