Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Require Collections for simple_* methods. #11580

Merged
merged 8 commits into from
Dec 15, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions synapse/storage/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,7 @@ async def simple_insert_many_values(
self,
table: str,
keys: Collection[str],
values: Iterable[Iterable[Any]],
values: Collection[Collection[Any]],
desc: str,
) -> None:
"""Executes an INSERT query on the named table.
Expand Down Expand Up @@ -1427,7 +1427,7 @@ async def simple_select_one(
self,
table: str,
keyvalues: Dict[str, Any],
retcols: Iterable[str],
retcols: Collection[str],
allow_none: Literal[False] = False,
desc: str = "simple_select_one",
) -> Dict[str, Any]:
Expand All @@ -1438,7 +1438,7 @@ async def simple_select_one(
self,
table: str,
keyvalues: Dict[str, Any],
retcols: Iterable[str],
retcols: Collection[str],
allow_none: Literal[True] = True,
desc: str = "simple_select_one",
) -> Optional[Dict[str, Any]]:
Expand All @@ -1448,7 +1448,7 @@ async def simple_select_one(
self,
table: str,
keyvalues: Dict[str, Any],
retcols: Iterable[str],
retcols: Collection[str],
allow_none: bool = False,
desc: str = "simple_select_one",
) -> Optional[Dict[str, Any]]:
Expand Down Expand Up @@ -1618,7 +1618,7 @@ async def simple_select_list(
self,
table: str,
keyvalues: Optional[Dict[str, Any]],
retcols: Iterable[str],
retcols: Collection[str],
desc: str = "simple_select_list",
) -> List[Dict[str, Any]]:
"""Executes a SELECT query on the named table, which may return zero or
Expand Down Expand Up @@ -1680,8 +1680,8 @@ async def simple_select_many_batch(
self,
table: str,
column: str,
iterable: Iterable[Any],
retcols: Iterable[str],
iterable: Collection[Any],
retcols: Collection[str],
keyvalues: Optional[Dict[str, Any]] = None,
desc: str = "simple_select_many_batch",
batch_size: int = 100,
Expand Down Expand Up @@ -1853,7 +1853,7 @@ def simple_select_one_txn(
txn: LoggingTransaction,
table: str,
keyvalues: Dict[str, Any],
retcols: Iterable[str],
retcols: Collection[str],
allow_none: bool = False,
) -> Optional[Dict[str, Any]]:
select_sql = "SELECT %s FROM %s WHERE %s" % (
Expand Down Expand Up @@ -2146,7 +2146,7 @@ async def simple_search_list(
table: str,
term: Optional[str],
col: str,
retcols: Iterable[str],
retcols: Collection[str],
desc="simple_search_list",
) -> Optional[List[Dict[str, Any]]]:
"""Executes a SELECT query on the named table, which may return zero or
Expand Down
23 changes: 1 addition & 22 deletions synapse/storage/databases/main/pusher.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from synapse.storage.util.id_generators import StreamIdGenerator
from synapse.types import JsonDict
from synapse.util import json_encoder
from synapse.util.caches.descriptors import cached, cachedList
from synapse.util.caches.descriptors import cached

if TYPE_CHECKING:
from synapse.server import HomeServer
Expand Down Expand Up @@ -196,27 +196,6 @@ async def get_if_user_has_pusher(self, user_id: str):
# This only exists for the cachedList decorator
raise NotImplementedError()

@cachedList(
cached_method_name="get_if_user_has_pusher",
list_name="user_ids",
num_args=1,
)
async def get_if_users_have_pushers(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was unused since #8059 as far as I can tell.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The signature of this is now "fine" that it could stay and mypy won't complain, but if it is unused...I think we should remove it?

self, user_ids: Iterable[str]
) -> Dict[str, bool]:
rows = await self.db_pool.simple_select_many_batch(
table="pushers",
column="user_name",
iterable=user_ids,
retcols=["user_name"],
desc="get_if_users_have_pushers",
)

result = {user_id: False for user_id in user_ids}
result.update({r["user_name"]: True for r in rows})

return result

async def update_pusher_last_stream_ordering(
self, app_id, pushkey, user_id, last_stream_ordering
) -> None:
Expand Down
4 changes: 2 additions & 2 deletions synapse/storage/databases/main/user_erasure_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import Dict, Iterable
from typing import Collection, Dict

from synapse.storage.database import LoggingTransaction
from synapse.storage.databases.main import CacheInvalidationWorkerStore
Expand Down Expand Up @@ -40,7 +40,7 @@ async def is_user_erased(self, user_id: str) -> bool:
return bool(result)

@cachedList(cached_method_name="is_user_erased", list_name="user_ids")
async def are_users_erased(self, user_ids: Iterable[str]) -> Dict[str, bool]:
async def are_users_erased(self, user_ids: Collection[str]) -> Dict[str, bool]:
"""
Checks which users in a list have requested erasure

Expand Down
2 changes: 1 addition & 1 deletion synapse/storage/databases/state/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ def _purge_unreferenced_state_groups(
)

async def get_previous_state_groups(
self, state_groups: Iterable[int]
self, state_groups: Collection[int]
) -> Dict[int, int]:
"""Fetch the previous groups of the given state groups.

Expand Down
2 changes: 1 addition & 1 deletion synapse/visibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ async def filter_events_for_client(
if isinstance(ignored_users_dict, dict):
ignore_list = frozenset(ignored_users_dict.keys())

erased_senders = await storage.main.are_users_erased(e.sender for e in events)
erased_senders = await storage.main.are_users_erased([e.sender for e in events])

if filter_send_to_client:
room_ids = {e.room_id for e in events}
Expand Down