mirror of
https://mau.dev/maunium/synapse.git
synced 2024-12-14 17:23:53 +01:00
Use namedtuple as return value
This commit is contained in:
parent
ba02bba88c
commit
232beb3a3c
2 changed files with 18 additions and 4 deletions
|
@ -66,7 +66,9 @@ class SearchHandler(BaseHandler):
|
||||||
|
|
||||||
room_ids = filtr.filter_rooms(room_ids)
|
room_ids = filtr.filter_rooms(room_ids)
|
||||||
|
|
||||||
rank_map, event_map = yield self.store.search_msgs(room_ids, search_term, keys)
|
rank_map, event_map, _ = yield self.store.search_msgs(
|
||||||
|
room_ids, search_term, keys
|
||||||
|
)
|
||||||
|
|
||||||
filtered_events = filtr.filter(event_map.values())
|
filtered_events = filtr.filter(event_map.values())
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,17 @@ from twisted.internet import defer
|
||||||
from _base import SQLBaseStore
|
from _base import SQLBaseStore
|
||||||
from synapse.storage.engines import PostgresEngine, Sqlite3Engine
|
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):
|
class SearchStore(SQLBaseStore):
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
|
@ -31,7 +42,7 @@ class SearchStore(SQLBaseStore):
|
||||||
"content.body", "content.name", "content.topic"
|
"content.body", "content.name", "content.topic"
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
2-tuple of (dict event_id -> rank, dict event_id -> event)
|
SearchResult
|
||||||
"""
|
"""
|
||||||
clauses = []
|
clauses = []
|
||||||
args = []
|
args = []
|
||||||
|
@ -85,11 +96,12 @@ class SearchStore(SQLBaseStore):
|
||||||
for ev in events
|
for ev in events
|
||||||
}
|
}
|
||||||
|
|
||||||
defer.returnValue((
|
defer.returnValue(SearchResult(
|
||||||
{
|
{
|
||||||
r["event_id"]: r["rank"]
|
r["event_id"]: r["rank"]
|
||||||
for r in results
|
for r in results
|
||||||
if r["event_id"] in event_map
|
if r["event_id"] in event_map
|
||||||
},
|
},
|
||||||
event_map
|
event_map,
|
||||||
|
None
|
||||||
))
|
))
|
||||||
|
|
Loading…
Reference in a new issue