diff options
author | Will Hunt <will@half-shot.uk> | 2020-10-13 10:55:35 +0100 |
---|---|---|
committer | Will Hunt <will@half-shot.uk> | 2020-10-13 10:56:36 +0100 |
commit | 92bb4eb9f4a7d2650b3582d13536f29a9cfa7307 (patch) | |
tree | a242c849169691ad52285dc5069c57620f9da6a1 /synapse | |
parent | Save a few DB callsx (diff) | |
download | synapse-92bb4eb9f4a7d2650b3582d13536f29a9cfa7307.tar.xz |
Tidy up comments,docstring and fix lint
Diffstat (limited to 'synapse')
-rw-r--r-- | synapse/appservice/__init__.py | 12 | ||||
-rw-r--r-- | synapse/appservice/api.py | 2 | ||||
-rw-r--r-- | synapse/appservice/scheduler.py | 2 | ||||
-rw-r--r-- | synapse/storage/databases/main/appservice.py | 10 | ||||
-rw-r--r-- | synapse/storage/databases/main/receipts.py | 13 |
5 files changed, 16 insertions, 23 deletions
diff --git a/synapse/appservice/__init__.py b/synapse/appservice/__init__.py index 728cc7849d..d4a2f02fc2 100644 --- a/synapse/appservice/__init__.py +++ b/synapse/appservice/__init__.py @@ -14,7 +14,7 @@ # limitations under the License. import logging import re -from typing import TYPE_CHECKING, List, Optional, Match, Iterable +from typing import TYPE_CHECKING, Iterable, List, Match, Optional from synapse.api.constants import EventTypes from synapse.events import EventBase @@ -132,7 +132,7 @@ class ApplicationService: raise ValueError("Expected string for 'regex' in ns '%s'" % ns) return namespaces - def _matches_regex(self, test_string: str, namespace_key: str)-> Optional[Match]: + def _matches_regex(self, test_string: str, namespace_key: str) -> Optional[Match]: for regex_obj in self.namespaces[namespace_key]: if regex_obj["regex"].match(test_string): return regex_obj @@ -255,7 +255,7 @@ class ApplicationService: def is_interested_in_user(self, user_id: str) -> bool: return ( - self._matches_regex(user_id, ApplicationService.NS_USERS) + bool(self._matches_regex(user_id, ApplicationService.NS_USERS)) or user_id == self.sender ) @@ -290,7 +290,7 @@ class ApplicationService: if regex_obj["exclusive"] ] - def get_groups_for_user(self, user_id: str)-> Iterable[str]: + def get_groups_for_user(self, user_id: str) -> Iterable[str]: """Get the groups that this user is associated with by this AS Args: @@ -324,7 +324,7 @@ class AppServiceTransaction: service: ApplicationService, id: int, events: List[EventBase], - ephemeral: Optional[List[JsonDict]] = None, + ephemeral: List[JsonDict], ): self.service = service self.id = id @@ -335,7 +335,7 @@ class AppServiceTransaction: """Sends this transaction using the provided AS API interface. Args: - as_api(ApplicationServiceApi): The API to use to send. + as_api: The API to use to send. Returns: True if the transaction was sent. """ diff --git a/synapse/appservice/api.py b/synapse/appservice/api.py index e16912814c..01d5c208cc 100644 --- a/synapse/appservice/api.py +++ b/synapse/appservice/api.py @@ -206,7 +206,7 @@ class ApplicationServiceApi(SimpleHttpClient): self, service: "ApplicationService", events: List[EventBase], - ephemeral: Optional[List[JsonDict]] = None, + ephemeral: List[JsonDict], txn_id: Optional[int] = None, ): if service.url is None: diff --git a/synapse/appservice/scheduler.py b/synapse/appservice/scheduler.py index 7aa534d65d..a55bc119cb 100644 --- a/synapse/appservice/scheduler.py +++ b/synapse/appservice/scheduler.py @@ -49,7 +49,7 @@ This is all tied together by the AppServiceScheduler which DIs the required components. """ import logging -from typing import Any, List, Optional +from typing import List, Optional from synapse.appservice import ApplicationService, ApplicationServiceState from synapse.events import EventBase diff --git a/synapse/storage/databases/main/appservice.py b/synapse/storage/databases/main/appservice.py index f7241c65b3..62e4692ace 100644 --- a/synapse/storage/databases/main/appservice.py +++ b/synapse/storage/databases/main/appservice.py @@ -15,7 +15,7 @@ # limitations under the License. import logging import re -from typing import List, Optional +from typing import List from synapse.appservice import ApplicationService, AppServiceTransaction from synapse.config.appservice import load_appservices @@ -179,14 +179,16 @@ class ApplicationServiceTransactionWorkerStore( self, service: ApplicationService, events: List[EventBase], - ephemeral: Optional[JsonDict] = None, + ephemeral: List[JsonDict], ) -> AppServiceTransaction: """Atomically creates a new transaction for this application service - with the given list of events. + with the given list of events. Ephemeral events are NOT persisted to the + database and are not resent if a transaction is retried. Args: service: The service who the transaction is for. - events: A list of events to put in the transaction. + events: A list of persistent events to put in the transaction. + ephemeral: A list of ephemeral events to put in the transaction. Returns: A new transaction. diff --git a/synapse/storage/databases/main/receipts.py b/synapse/storage/databases/main/receipts.py index 66862acb7d..dbb4887985 100644 --- a/synapse/storage/databases/main/receipts.py +++ b/synapse/storage/databases/main/receipts.py @@ -123,15 +123,6 @@ class ReceiptsWorkerStore(SQLBaseStore, metaclass=abc.ABCMeta): for row in rows } - async def get_linearized_receipts_for_all_rooms( - self, to_key: int, from_key: Optional[int] = None - ) -> List[dict]: - results = await self._get_linearized_receipts_for_all_rooms( - to_key, from_key=from_key - ) - - return results - async def get_linearized_receipts_for_rooms( self, room_ids: List[str], to_key: int, from_key: Optional[int] = None ) -> List[dict]: @@ -284,7 +275,7 @@ class ReceiptsWorkerStore(SQLBaseStore, metaclass=abc.ABCMeta): return results @cached(num_args=2,) - async def _get_linearized_receipts_for_all_rooms( + async def get_linearized_receipts_for_all_rooms( self, to_key: int, from_key: Optional[int] = None ): def f(txn): @@ -305,7 +296,7 @@ class ReceiptsWorkerStore(SQLBaseStore, metaclass=abc.ABCMeta): return self.db_pool.cursor_to_dict(txn) txn_results = await self.db_pool.runInteraction( - "_get_linearized_receipts_for_all_rooms", f + "get_linearized_receipts_for_all_rooms", f ) results = {} |