diff options
author | Erik Johnston <erik@matrix.org> | 2015-10-22 15:02:35 +0100 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2015-10-22 15:02:35 +0100 |
commit | 232beb3a3c28ccdc5388daa9396d5054b7768b12 (patch) | |
tree | 8ad28ddbf431e3107272760586565cb68be04934 /synapse/storage | |
parent | Limit max number of SQL vars (diff) | |
download | synapse-232beb3a3c28ccdc5388daa9396d5054b7768b12.tar.xz |
Use namedtuple as return value
Diffstat (limited to 'synapse/storage')
-rw-r--r-- | synapse/storage/search.py | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/synapse/storage/search.py b/synapse/storage/search.py index 810b5406ad..41451ade57 100644 --- a/synapse/storage/search.py +++ b/synapse/storage/search.py @@ -18,6 +18,17 @@ from twisted.internet import defer from _base import SQLBaseStore from synapse.storage.engines import PostgresEngine, Sqlite3Engine +from collections import namedtuple + +"""The result of a search. + +Fields: + rank_map (dict): Mapping event_id -> rank + event_map (dict): Mapping event_id -> event + pagination_token (str): Pagination token +""" +SearchResult = namedtuple("SearchResult", ("rank_map", "event_map", "pagination_token")) + class SearchStore(SQLBaseStore): @defer.inlineCallbacks @@ -31,7 +42,7 @@ class SearchStore(SQLBaseStore): "content.body", "content.name", "content.topic" Returns: - 2-tuple of (dict event_id -> rank, dict event_id -> event) + SearchResult """ clauses = [] args = [] @@ -85,11 +96,12 @@ class SearchStore(SQLBaseStore): for ev in events } - defer.returnValue(( + defer.returnValue(SearchResult( { r["event_id"]: r["rank"] for r in results if r["event_id"] in event_map }, - event_map + event_map, + None )) |