Refactor search code to reduce function size. (#11991)

Splits the search code into a few logical functions instead of a single
unreadable function.

There are also a few additional changes for readability.

After refactoring it was clear to see there were some unused and
unnecessary variables, which were simplified.
This commit is contained in:
Patrick Cloke 2022-02-15 08:47:05 -05:00 committed by GitHub
parent 45f45404de
commit e44f91d678
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 436 additions and 227 deletions

View file

@ -28,6 +28,7 @@ from synapse.storage.database import (
)
from synapse.storage.databases.main.events_worker import EventRedactBehaviour
from synapse.storage.engines import PostgresEngine, Sqlite3Engine
from synapse.types import JsonDict
if TYPE_CHECKING:
from synapse.server import HomeServer
@ -381,17 +382,19 @@ class SearchStore(SearchBackgroundUpdateStore):
):
super().__init__(database, db_conn, hs)
async def search_msgs(self, room_ids, search_term, keys):
async def search_msgs(
self, room_ids: Collection[str], search_term: str, keys: Iterable[str]
) -> JsonDict:
"""Performs a full text search over events with given keys.
Args:
room_ids (list): List of room ids to search in
search_term (str): Search term to search for
keys (list): List of keys to search in, currently supports
room_ids: List of room ids to search in
search_term: Search term to search for
keys: List of keys to search in, currently supports
"content.body", "content.name", "content.topic"
Returns:
list of dicts
Dictionary of results
"""
clauses = []
@ -499,10 +502,10 @@ class SearchStore(SearchBackgroundUpdateStore):
self,
room_ids: Collection[str],
search_term: str,
keys: List[str],
keys: Iterable[str],
limit,
pagination_token: Optional[str] = None,
) -> List[dict]:
) -> JsonDict:
"""Performs a full text search over events with given keys.
Args: