From fd5c28dc52f591734b5f3eb465b283761e1116f3 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Tue, 12 Jan 2016 10:55:11 +0000 Subject: [PATCH 1/3] Dont fire user_joined_room when guest hits /events Firing the 'user_joined_room' signal everytime a guest hits /events causes all presence for that room to be returned in the stream. This may sound helpful, but causes clients to tightloop calling /events. In general, guest users should get the initial presence from (room) intial sync and so we don't require presence to sbsequently come down the event stream. --- synapse/handlers/events.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/synapse/handlers/events.py b/synapse/handlers/events.py index 28c674730e..c73eec2b91 100644 --- a/synapse/handlers/events.py +++ b/synapse/handlers/events.py @@ -36,10 +36,6 @@ def stopped_user_eventstream(distributor, user): return distributor.fire("stopped_user_eventstream", user) -def user_joined_room(distributor, user, room_id): - return distributor.fire("user_joined_room", user, room_id) - - class EventStreamHandler(BaseHandler): def __init__(self, hs): @@ -136,9 +132,6 @@ class EventStreamHandler(BaseHandler): # thundering herds on restart. timeout = random.randint(int(timeout*0.9), int(timeout*1.1)) - if is_guest: - yield user_joined_room(self.distributor, auth_user, room_id) - events, tokens = yield self.notifier.get_events_for( auth_user, pagin_config, timeout, only_room_events=only_room_events, From 70dfe4dc96519a20535dbd1b250d4359b6e93125 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Tue, 12 Jan 2016 15:01:56 +0000 Subject: [PATCH 2/3] Don't include old left rooms --- synapse/handlers/sync.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/synapse/handlers/sync.py b/synapse/handlers/sync.py index 27fdbe28ee..33c1a4512c 100644 --- a/synapse/handlers/sync.py +++ b/synapse/handlers/sync.py @@ -585,7 +585,8 @@ class SyncHandler(BaseHandler): sync_config, leave_event, since_token, tags_by_room, account_data_by_room ) - archived.append(room_sync) + if room_sync: + archived.append(room_sync) invited = [ InvitedSyncResult(room_id=event.room_id, invite=event) @@ -726,6 +727,9 @@ class SyncHandler(BaseHandler): leave_token = since_token.copy_and_replace("room_key", stream_token) + if since_token.is_after(leave_token): + defer.returnValue(None) + batch = yield self.load_filtered_recents( leave_event.room_id, sync_config, leave_token, since_token, ) From 8740e4e94a6de62680db2b6c7b9f9bfda244d8ae Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Wed, 13 Jan 2016 11:37:17 +0000 Subject: [PATCH 3/3] bulk_get_push_rules should handle empty lists --- synapse/storage/push_rule.py | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) diff --git a/synapse/storage/push_rule.py b/synapse/storage/push_rule.py index 0829262f42..24d137f8ca 100644 --- a/synapse/storage/push_rule.py +++ b/synapse/storage/push_rule.py @@ -57,43 +57,35 @@ class PushRuleStore(SQLBaseStore): @defer.inlineCallbacks def bulk_get_push_rules(self, user_ids): + if not user_ids: + defer.returnValue({}) + batch_size = 100 def f(txn, user_ids_to_fetch): sql = ( - "SELECT " + - ",".join("pr."+x for x in PushRuleTable.fields) + - " FROM " + PushRuleTable.table_name + " pr " + - " LEFT JOIN " + PushRuleEnableTable.table_name + " pre " + - " ON pr.user_name = pre.user_name and pr.rule_id = pre.rule_id " + - " WHERE pr.user_name " + + "SELECT pr.*" + " FROM push_rules as pr " + " LEFT JOIN push_rules_enable as pre " + " ON pr.user_name = pre.user_name and pr.rule_id = pre.rule_id " + " WHERE pr.user_name " " IN (" + ",".join("?" for _ in user_ids_to_fetch) + ")" " AND (pre.enabled is null or pre.enabled = 1)" " ORDER BY pr.user_name, pr.priority_class DESC, pr.priority DESC" ) txn.execute(sql, user_ids_to_fetch) - return txn.fetchall() + return self.cursor_to_dict(txn) results = {} - batch_start = 0 - while batch_start < len(user_ids): - batch_end = min(len(user_ids), batch_size) - batch_user_ids = user_ids[batch_start:batch_end] - batch_start = batch_end - + chunks = [user_ids[i:i+batch_size] for i in xrange(0, len(user_ids), batch_size)] + for batch_user_ids in chunks: rows = yield self.runInteraction( "bulk_get_push_rules", f, batch_user_ids ) - for r in rows: - rawdict = { - PushRuleTable.fields[i]: r[i] for i in range(len(r)) - } - - if rawdict['user_name'] not in results: - results[rawdict['user_name']] = [] - results[rawdict['user_name']].append(rawdict) + for row in rows: + results.setdefault(row['user_name'], []).append(row) defer.returnValue(results) @defer.inlineCallbacks