Extract adding clients to the various dicts to a function.

(imported from commit 667e5736710c23becdf4ebe5688a31421ac632f5)
This commit is contained in:
Tim Abbott 2013-12-13 14:59:56 -05:00
parent af347acf99
commit 7c829c4024
1 changed files with 7 additions and 6 deletions

View File

@ -286,6 +286,11 @@ def get_client_descriptors_for_user(user_profile_id):
def get_client_descriptors_for_realm_all_streams(realm_id):
return realm_clients_all_streams.get(realm_id, [])
def add_to_client_dicts(client):
user_clients.setdefault(client.user_profile_id, []).append(client)
if client.all_public_streams:
realm_clients_all_streams.setdefault(client.realm_id, []).append(client)
def allocate_client_descriptor(user_profile_id, realm_id, event_types, client_type,
apply_markdown, all_public_streams, lifespan_secs,
narrow=[]):
@ -295,9 +300,7 @@ def allocate_client_descriptor(user_profile_id, realm_id, event_types, client_ty
client = ClientDescriptor(user_profile_id, realm_id, EventQueue(id), event_types, client_type,
apply_markdown, all_public_streams, lifespan_secs, narrow)
clients[id] = client
user_clients.setdefault(user_profile_id, []).append(client)
if all_public_streams:
realm_clients_all_streams.setdefault(realm_id, []).append(client)
add_to_client_dicts(client)
return client
def do_gc_event_queues(to_remove, affected_users, affected_realms):
@ -381,9 +384,7 @@ def load_event_queues():
for client in clients.itervalues():
# Put code for migrations due to event queue data format changes here
user_clients.setdefault(client.user_profile_id, []).append(client)
if client.all_public_streams:
realm_clients_all_streams.setdefault(client.realm_id, []).append(client)
add_to_client_dicts(client)
logging.info('Tornado loaded %d event queues in %.3fs'
% (len(clients), time.time() - start))