0
0
Fork 1
mirror of https://mau.dev/maunium/synapse.git synced 2024-11-17 15:31:19 +01:00

Limit number of things we fetch out of the db

This commit is contained in:
Erik Johnston 2017-05-31 16:17:58 +01:00
parent 304880d185
commit 63c58c2a3f

View file

@ -207,16 +207,37 @@ class UserDirectoryStore(SQLBaseStore):
if not self._curr_state_delta_stream_cache.has_any_entity_changed(prev_stream_id): if not self._curr_state_delta_stream_cache.has_any_entity_changed(prev_stream_id):
return [] return []
# TODO: Add limit def get_current_state_deltas_txn(txn):
sql = """ # First we calculate the max stream id that will give us less than
SELECT stream_id, room_id, type, state_key, event_id, prev_event_id # N results
FROM current_state_delta_stream sql = """
WHERE stream_id > ? SELECT stream_id, count(*)
ORDER BY stream_id ASC FROM current_state_delta_stream
""" WHERE stream_id > ?
GROUP BY stream_id
ORDER BY stream_id ASC
LIMIT 100
"""
txn.execute(sql, (prev_stream_id,))
return self._execute( total = 0
"get_current_state_deltas", self.cursor_to_dict, sql, prev_stream_id for max_stream_id, count in txn:
total += count
if total > 50:
break
# Now actually get the deltas
sql = """
SELECT stream_id, room_id, type, state_key, event_id, prev_event_id
FROM current_state_delta_stream
WHERE ? < stream_id AND stream_id <= ?
ORDER BY stream_id ASC
"""
txn.execute(sql, (prev_stream_id, max_stream_id,))
return self.cursor_to_dict(txn)
return self.runInteraction(
"get_current_state_deltas", get_current_state_deltas_txn
) )
def get_max_stream_id_in_current_state_deltas(self): def get_max_stream_id_in_current_state_deltas(self):