mirror of https://github.com/zulip/zulip.git
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)
This commit is contained in:
parent
d17db6687c
commit
f817bf6144
|
@ -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)
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
Loading…
Reference in New Issue