diff options
author | Erik Johnston <erik@matrix.org> | 2015-03-09 15:16:25 +0000 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2015-03-09 15:16:25 +0000 |
commit | a8dbb624b3fb991e520e0af909a200c3f4bc53f7 (patch) | |
tree | 0661aad63ca938e63f5ca1c956423387be12a47e | |
parent | Merge branch 'release-v0.8.0' of github.com:matrix-org/synapse (diff) | |
download | synapse-github/initial_sync_perf.tar.xz |
Optimize/coerce query to use correct indices github/initial_sync_perf initial_sync_perf
-rw-r--r-- | synapse/storage/stream.py | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/synapse/storage/stream.py b/synapse/storage/stream.py index 09bc522210..e320da1524 100644 --- a/synapse/storage/stream.py +++ b/synapse/storage/stream.py @@ -358,7 +358,7 @@ class StreamStore(SQLBaseStore): sql = ( "SELECT stream_ordering, topological_ordering, event_id" " 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" " LIMIT ?" ) @@ -368,21 +368,29 @@ class StreamStore(SQLBaseStore): "SELECT stream_ordering, topological_ordering, event_id" " FROM events" " WHERE room_id = ? AND stream_ordering > ?" - " AND stream_ordering <= ? AND outlier = 0" + " AND outlier = 0" " ORDER BY topological_ordering DESC, stream_ordering DESC" " LIMIT ?" ) def get_recent_events_for_room_txn(txn): if from_token is None: - txn.execute(sql, (room_id, end_token.stream, limit,)) + txn.execute(sql, (room_id, limit*2,)) else: 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[:] = [ + r + for r in rows + if r["stream_ordering"] <= end_token.stream + ] + + rows[:] = rows[:int(limit)] + rows.reverse() # As we selected with reverse ordering if rows: |