mirror of
https://github.com/element-hq/synapse.git
synced 2024-11-24 18:45:52 +03:00
Optimize/coerce query to use correct indices
This commit is contained in:
parent
d5174065af
commit
a8dbb624b3
1 changed files with 12 additions and 4 deletions
|
@ -358,7 +358,7 @@ class StreamStore(SQLBaseStore):
|
||||||
sql = (
|
sql = (
|
||||||
"SELECT stream_ordering, topological_ordering, event_id"
|
"SELECT stream_ordering, topological_ordering, event_id"
|
||||||
" FROM events"
|
" FROM events"
|
||||||
" WHERE room_id = ? AND stream_ordering <= ? AND outlier = 0"
|
" WHERE room_id = ? AND outlier = 0"
|
||||||
" ORDER BY topological_ordering DESC, stream_ordering DESC"
|
" ORDER BY topological_ordering DESC, stream_ordering DESC"
|
||||||
" LIMIT ?"
|
" LIMIT ?"
|
||||||
)
|
)
|
||||||
|
@ -368,21 +368,29 @@ class StreamStore(SQLBaseStore):
|
||||||
"SELECT stream_ordering, topological_ordering, event_id"
|
"SELECT stream_ordering, topological_ordering, event_id"
|
||||||
" FROM events"
|
" FROM events"
|
||||||
" WHERE room_id = ? AND stream_ordering > ?"
|
" WHERE room_id = ? AND stream_ordering > ?"
|
||||||
" AND stream_ordering <= ? AND outlier = 0"
|
" AND outlier = 0"
|
||||||
" ORDER BY topological_ordering DESC, stream_ordering DESC"
|
" ORDER BY topological_ordering DESC, stream_ordering DESC"
|
||||||
" LIMIT ?"
|
" LIMIT ?"
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_recent_events_for_room_txn(txn):
|
def get_recent_events_for_room_txn(txn):
|
||||||
if from_token is None:
|
if from_token is None:
|
||||||
txn.execute(sql, (room_id, end_token.stream, limit,))
|
txn.execute(sql, (room_id, limit*2,))
|
||||||
else:
|
else:
|
||||||
txn.execute(sql, (
|
txn.execute(sql, (
|
||||||
room_id, from_token.stream, end_token.stream, limit
|
room_id, from_token.stream, limit*2
|
||||||
))
|
))
|
||||||
|
|
||||||
rows = self.cursor_to_dict(txn)
|
rows = self.cursor_to_dict(txn)
|
||||||
|
|
||||||
|
rows[:] = [
|
||||||
|
r
|
||||||
|
for r in rows
|
||||||
|
if r["stream_ordering"] <= end_token.stream
|
||||||
|
]
|
||||||
|
|
||||||
|
rows[:] = rows[:int(limit)]
|
||||||
|
|
||||||
rows.reverse() # As we selected with reverse ordering
|
rows.reverse() # As we selected with reverse ordering
|
||||||
|
|
||||||
if rows:
|
if rows:
|
||||||
|
|
Loading…
Reference in a new issue