mirror of
https://mau.dev/maunium/synapse.git
synced 2024-09-04 08:32:29 +00:00
Limit number of things we fetch out of the db
This commit is contained in:
parent
304880d185
commit
63c58c2a3f
@ -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):
|
||||||
|
# First we calculate the max stream id that will give us less than
|
||||||
|
# N results
|
||||||
|
sql = """
|
||||||
|
SELECT stream_id, count(*)
|
||||||
|
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,))
|
||||||
|
|
||||||
|
total = 0
|
||||||
|
for max_stream_id, count in txn:
|
||||||
|
total += count
|
||||||
|
if total > 50:
|
||||||
|
break
|
||||||
|
|
||||||
|
# Now actually get the deltas
|
||||||
sql = """
|
sql = """
|
||||||
SELECT stream_id, room_id, type, state_key, event_id, prev_event_id
|
SELECT stream_id, room_id, type, state_key, event_id, prev_event_id
|
||||||
FROM current_state_delta_stream
|
FROM current_state_delta_stream
|
||||||
WHERE stream_id > ?
|
WHERE ? < stream_id AND stream_id <= ?
|
||||||
ORDER BY stream_id ASC
|
ORDER BY stream_id ASC
|
||||||
"""
|
"""
|
||||||
|
txn.execute(sql, (prev_stream_id, max_stream_id,))
|
||||||
|
return self.cursor_to_dict(txn)
|
||||||
|
|
||||||
return self._execute(
|
return self.runInteraction(
|
||||||
"get_current_state_deltas", self.cursor_to_dict, sql, prev_stream_id
|
"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):
|
||||||
|
Loading…
Reference in New Issue
Block a user