mirror of
https://mau.dev/maunium/synapse.git
synced 2024-08-26 20:22:22 +00:00
Use a query that postgresql optimises better for get_events_around
This commit is contained in:
parent
1238203bc4
commit
f18d7546c6
@ -591,25 +591,28 @@ class StreamStore(SQLBaseStore):
|
|||||||
|
|
||||||
query_before = (
|
query_before = (
|
||||||
"SELECT topological_ordering, stream_ordering, event_id FROM events"
|
"SELECT topological_ordering, stream_ordering, event_id FROM events"
|
||||||
" WHERE room_id = ? AND (topological_ordering < ?"
|
" WHERE room_id = ? AND topological_ordering < ?"
|
||||||
" OR (topological_ordering = ? AND stream_ordering < ?))"
|
" UNION ALL "
|
||||||
" ORDER BY topological_ordering DESC, stream_ordering DESC"
|
" SELECT topological_ordering, stream_ordering, event_id FROM events"
|
||||||
" LIMIT ?"
|
" WHERE room_id = ? AND topological_ordering = ? AND stream_ordering < ?"
|
||||||
|
" ORDER BY topological_ordering DESC, stream_ordering DESC LIMIT ?"
|
||||||
)
|
)
|
||||||
|
|
||||||
query_after = (
|
query_after = (
|
||||||
"SELECT topological_ordering, stream_ordering, event_id FROM events"
|
"SELECT topological_ordering, stream_ordering, event_id FROM events"
|
||||||
" WHERE room_id = ? AND (topological_ordering > ?"
|
" WHERE room_id = ? AND topological_ordering > ?"
|
||||||
" OR (topological_ordering = ? AND stream_ordering > ?))"
|
" UNION ALL"
|
||||||
" ORDER BY topological_ordering ASC, stream_ordering ASC"
|
" SELECT topological_ordering, stream_ordering, event_id FROM events"
|
||||||
" LIMIT ?"
|
" WHERE room_id = ? AND topological_ordering = ? AND stream_ordering > ?"
|
||||||
|
" ORDER BY topological_ordering ASC, stream_ordering ASC LIMIT ?"
|
||||||
)
|
)
|
||||||
|
|
||||||
txn.execute(
|
txn.execute(
|
||||||
query_before,
|
query_before,
|
||||||
(
|
(
|
||||||
room_id, topological_ordering, topological_ordering,
|
room_id, topological_ordering,
|
||||||
stream_ordering, before_limit,
|
room_id, topological_ordering, stream_ordering,
|
||||||
|
before_limit,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -630,8 +633,9 @@ class StreamStore(SQLBaseStore):
|
|||||||
txn.execute(
|
txn.execute(
|
||||||
query_after,
|
query_after,
|
||||||
(
|
(
|
||||||
room_id, topological_ordering, topological_ordering,
|
room_id, topological_ordering,
|
||||||
stream_ordering, after_limit,
|
room_id, topological_ordering, stream_ordering,
|
||||||
|
after_limit,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user