mirror of https://github.com/zulip/zulip.git
Have client and server exchange a server generation number
This will allow the client to detect when the server has restarted. (imported from commit 89e75916719d967beb2520be6263f79f897d9ec1)
This commit is contained in:
parent
24c1a2d7f1
commit
103bf321b4
|
@ -50,6 +50,7 @@
|
|||
|
||||
{# Not escaped, because it's guaranteed by the model to be an integer. #}
|
||||
var initial_pointer = {{ user_profile.pointer }};
|
||||
var server_generation = {{ server_generation }};
|
||||
|
||||
var email = "{{ user_profile.user.email|escapejs }}";
|
||||
var have_initial_messages = {{ have_initial_messages|escapejs }};
|
||||
|
|
|
@ -7,6 +7,7 @@ var globals =
|
|||
|
||||
// index.html
|
||||
+ ' initial_pointer email stream_list people_list have_initial_messages'
|
||||
+ ' server_generation'
|
||||
|
||||
// compose.js
|
||||
+ ' show_compose hide_compose toggle_compose clear_compose_box compose_button'
|
||||
|
|
|
@ -57,9 +57,12 @@ var selected_message; // = get_message_row(selected_message_id)
|
|||
var received = {
|
||||
first: -1,
|
||||
last: -1,
|
||||
failures: 0
|
||||
failures: 0,
|
||||
server_generation: -1 /* to be filled in on document.ready */
|
||||
};
|
||||
|
||||
$(function () { received.server_generation = server_generation; });
|
||||
|
||||
// The "message groups", i.e. blocks of messages collapsed by recipient.
|
||||
// Each message table has a list of lists.
|
||||
var message_groups = {
|
||||
|
|
|
@ -28,6 +28,9 @@ import socket
|
|||
import re
|
||||
import hashlib
|
||||
import urllib
|
||||
import time
|
||||
|
||||
SERVER_GENERATION = int(time.time())
|
||||
|
||||
def require_post(view_func):
|
||||
def _wrapped_view_func(request, *args, **kwargs):
|
||||
|
@ -174,7 +177,8 @@ def home(request):
|
|||
'have_initial_messages':
|
||||
'true' if num_messages > 0 else 'false',
|
||||
'show_debug':
|
||||
settings.DEBUG and ('show_debug' in request.GET) },
|
||||
settings.DEBUG and ('show_debug' in request.GET),
|
||||
'server_generation': SERVER_GENERATION},
|
||||
context_instance=RequestContext(request))
|
||||
|
||||
@login_required
|
||||
|
@ -203,12 +207,14 @@ def format_updates_response(messages, mit_sync_bot=False, apply_markdown=False,
|
|||
return {'messages': [message.to_dict(apply_markdown) for message in messages],
|
||||
"result": "success",
|
||||
"msg": "",
|
||||
'where': where}
|
||||
'where': where,
|
||||
'server_generation': SERVER_GENERATION}
|
||||
|
||||
def return_messages_immediately(request, handler, user_profile, **kwargs):
|
||||
first = request.POST.get("first")
|
||||
last = request.POST.get("last")
|
||||
failures = request.POST.get("failures")
|
||||
client_server_generation = request.POST.get("server_generation")
|
||||
if first is None or last is None:
|
||||
# When an API user is first querying the server to subscribe,
|
||||
# there's no reason to reply immediately.
|
||||
|
@ -251,6 +257,12 @@ def return_messages_immediately(request, handler, user_profile, **kwargs):
|
|||
handler.finish(format_updates_response([], where="bottom", **kwargs))
|
||||
return True
|
||||
|
||||
if client_server_generation is not None and int(client_server_generation) != SERVER_GENERATION:
|
||||
# No messages, but still return immediately to inform the
|
||||
# client that they should reload
|
||||
handler.finish(format_updates_response([], where="bottom", **kwargs))
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
def get_updates_backend(request, user_profile, handler, **kwargs):
|
||||
|
|
Loading…
Reference in New Issue