diff options
author | Patrick Cloke <clokep@users.noreply.github.com> | 2023-10-05 11:07:38 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-05 11:07:38 -0400 |
commit | fa907025f4b263d27c2b338fb0fe86d257d74fa8 (patch) | |
tree | 325bfac7ba840c71a0b9a7b3e7a72e3549f03c54 /synapse/storage/databases/main/search.py | |
parent | Add __slots__ to replication commands. (#16429) (diff) | |
download | synapse-fa907025f4b263d27c2b338fb0fe86d257d74fa8.tar.xz |
Remove manys calls to cursor_to_dict (#16431)
This avoids calling cursor_to_dict and then immediately unpacking the values in the dict for other users. By not creating the intermediate dictionary we can avoid allocating the dictionary and strings for the keys, which should generally be more performant. Additionally this improves type hints by avoid Dict[str, Any] dictionaries coming out of the database layer.
Diffstat (limited to 'synapse/storage/databases/main/search.py')
-rw-r--r-- | synapse/storage/databases/main/search.py | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/synapse/storage/databases/main/search.py b/synapse/storage/databases/main/search.py index a7aae661d8..1d69c4a5f0 100644 --- a/synapse/storage/databases/main/search.py +++ b/synapse/storage/databases/main/search.py @@ -179,22 +179,24 @@ class SearchBackgroundUpdateStore(SearchWorkerStore): # store_search_entries_txn with a generator function, but that # would mean having two cursors open on the database at once. # Instead we just build a list of results. - rows = self.db_pool.cursor_to_dict(txn) + rows = txn.fetchall() if not rows: return 0 - min_stream_id = rows[-1]["stream_ordering"] + min_stream_id = rows[-1][0] event_search_rows = [] - for row in rows: + for ( + stream_ordering, + event_id, + room_id, + etype, + json, + origin_server_ts, + ) in rows: try: - event_id = row["event_id"] - room_id = row["room_id"] - etype = row["type"] - stream_ordering = row["stream_ordering"] - origin_server_ts = row["origin_server_ts"] try: - event_json = db_to_json(row["json"]) + event_json = db_to_json(json) content = event_json["content"] except Exception: continue |