mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2025-05-02 08:26:01 -04:00
Fix incredubly slow back pagination query
If a client didn't specify a from token when paginating backwards synapse would attempt to query the (global) maximum topological token. This a) doesn't make much sense since they're room specific and b) there are no indices that lets postgres do this efficiently.
This commit is contained in:
parent
a842fed418
commit
d04e2ff3a4
4 changed files with 48 additions and 12 deletions
|
@ -521,13 +521,20 @@ class StreamStore(SQLBaseStore):
|
|||
)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def get_room_events_max_id(self, direction='f'):
|
||||
def get_room_events_max_id(self, room_id=None):
|
||||
"""Returns the current token for rooms stream.
|
||||
|
||||
By default, it returns the current global stream token. Specifying a
|
||||
`room_id` causes it to return the current room specific topological
|
||||
token.
|
||||
"""
|
||||
token = yield self._stream_id_gen.get_current_token()
|
||||
if direction != 'b':
|
||||
if room_id is None:
|
||||
defer.returnValue("s%d" % (token,))
|
||||
else:
|
||||
topo = yield self.runInteraction(
|
||||
"_get_max_topological_txn", self._get_max_topological_txn
|
||||
"_get_max_topological_txn", self._get_max_topological_txn,
|
||||
room_id,
|
||||
)
|
||||
defer.returnValue("t%d-%d" % (topo, token))
|
||||
|
||||
|
@ -579,11 +586,11 @@ class StreamStore(SQLBaseStore):
|
|||
lambda r: r[0][0] if r else 0
|
||||
)
|
||||
|
||||
def _get_max_topological_txn(self, txn):
|
||||
def _get_max_topological_txn(self, txn, room_id):
|
||||
txn.execute(
|
||||
"SELECT MAX(topological_ordering) FROM events"
|
||||
" WHERE outlier = ?",
|
||||
(False,)
|
||||
" WHERE room_id = ?",
|
||||
(room_id,)
|
||||
)
|
||||
|
||||
rows = txn.fetchall()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue