mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 23:13:25 +00:00
Add a event_queue gc hook for missed messages
(imported from commit a799abb35a9622e6aa59e9499cab3281ccb6859f)
This commit is contained in:
@@ -118,8 +118,18 @@ clients = {}
|
||||
# maps user id to list of client descriptors
|
||||
user_clients = {}
|
||||
|
||||
# list of registered gc hooks.
|
||||
# each one will be called with a user profile id, queue, and bool
|
||||
# last_for_client that is true if this is the last queue pertaining
|
||||
# to this user_profile_id
|
||||
# that is about to be deleted
|
||||
gc_hooks = []
|
||||
|
||||
next_queue_id = 0
|
||||
|
||||
def add_client_gc_hook(hook):
|
||||
gc_hooks.append(hook)
|
||||
|
||||
def get_client_descriptor(queue_id):
|
||||
return clients.get(queue_id)
|
||||
|
||||
@@ -146,9 +156,6 @@ def gc_event_queues():
|
||||
to_remove.add(id)
|
||||
affected_users.add(client.user_profile_id)
|
||||
|
||||
for id in to_remove:
|
||||
del clients[id]
|
||||
|
||||
for user_id in affected_users:
|
||||
new_client_list = filter(lambda c: c.event_queue.id not in to_remove,
|
||||
user_clients[user_id])
|
||||
@@ -157,6 +164,11 @@ def gc_event_queues():
|
||||
else:
|
||||
user_clients[user_id] = new_client_list
|
||||
|
||||
for id in to_remove:
|
||||
for cb in gc_hooks:
|
||||
cb(clients[id].user_profile_id, clients[id], clients[id].user_profile_id not in user_clients)
|
||||
del clients[id]
|
||||
|
||||
logging.info(('Tornado removed %d idle event queues owned by %d users in %.3fs.'
|
||||
+ ' Now %d active queues')
|
||||
% (len(to_remove), len(affected_users), time.time() - start,
|
||||
|
||||
Reference in New Issue
Block a user