diff options
author | Erik Johnston <erik@matrix.org> | 2019-06-19 13:19:18 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-19 13:19:18 +0100 |
commit | e0be8d70164b814688261c598947979117f0aca0 (patch) | |
tree | c1fbee26a68bdc9db3e65a3886093fbff305ffc4 /synapse/storage | |
parent | Merge pull request #5490 from matrix-org/rav/xmlsec_in_docker (diff) | |
parent | Run as background process and fix comments (diff) | |
download | synapse-e0be8d70164b814688261c598947979117f0aca0.tar.xz |
Merge pull request #5480 from matrix-org/erikj/extremities_dummy_events
Add experimental option to reduce extremities.
Diffstat (limited to 'synapse/storage')
-rw-r--r-- | synapse/storage/event_federation.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/synapse/storage/event_federation.py b/synapse/storage/event_federation.py index 09e39c2c28..e8d16edbc8 100644 --- a/synapse/storage/event_federation.py +++ b/synapse/storage/event_federation.py @@ -190,6 +190,35 @@ class EventFederationWorkerStore(EventsWorkerStore, SignatureWorkerStore, SQLBas room_id, ) + def get_rooms_with_many_extremities(self, min_count, limit): + """Get the top rooms with at least N extremities. + + Args: + min_count (int): The minimum number of extremities + limit (int): The maximum number of rooms to return. + + Returns: + Deferred[list]: At most `limit` room IDs that have at least + `min_count` extremities, sorted by extremity count. + """ + + def _get_rooms_with_many_extremities_txn(txn): + sql = """ + SELECT room_id FROM event_forward_extremities + GROUP BY room_id + HAVING count(*) > ? + ORDER BY count(*) DESC + LIMIT ? + """ + + txn.execute(sql, (min_count, limit)) + return [room_id for room_id, in txn] + + return self.runInteraction( + "get_rooms_with_many_extremities", + _get_rooms_with_many_extremities_txn, + ) + @cached(max_entries=5000, iterable=True) def get_latest_event_ids_in_room(self, room_id): return self._simple_select_onecol( |