From d47c0ed60b4789e871cf1049111d757ac759bbcc Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Wed, 28 Oct 2020 11:27:18 +0000 Subject: [PATCH 1/6] Tie together matches_user_in_member_list and get_users_in_room --- synapse/appservice/__init__.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/synapse/appservice/__init__.py b/synapse/appservice/__init__.py index 3862d9c08f38..f70841ae8613 100644 --- a/synapse/appservice/__init__.py +++ b/synapse/appservice/__init__.py @@ -19,7 +19,7 @@ from synapse.api.constants import EventTypes from synapse.events import EventBase from synapse.types import GroupID, JsonDict, UserID, get_domain_from_id -from synapse.util.caches.descriptors import cached +from synapse.util.caches.descriptors import _CacheContext, cached if TYPE_CHECKING: from synapse.appservice.api import ApplicationServiceApi @@ -164,9 +164,9 @@ async def _matches_user( does_match = await self.matches_user_in_member_list(event.room_id, store) return does_match - @cached(num_args=1) + @cached(num_args=1, cache_context=True) async def matches_user_in_member_list( - self, room_id: str, store: "DataStore" + self, room_id: str, store: "DataStore", cache_context: _CacheContext, ) -> bool: """Check if this service is interested a room based upon it's membership @@ -177,7 +177,9 @@ async def matches_user_in_member_list( Returns: True if this service would like to know about this room. """ - member_list = await store.get_users_in_room(room_id) + member_list = await store.get_users_in_room( + room_id, on_invalidate=cache_context.invalidate + ) # check joined member events for user_id in member_list: From 67d160c54895e7e3cba0392492fb96f94c4ca7ae Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Wed, 28 Oct 2020 11:52:34 +0000 Subject: [PATCH 2/6] changelog --- changelog.d/8676.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/8676.bugfix diff --git a/changelog.d/8676.bugfix b/changelog.d/8676.bugfix new file mode 100644 index 000000000000..26afb6ef3104 --- /dev/null +++ b/changelog.d/8676.bugfix @@ -0,0 +1 @@ +Fix a bug where an appservice may not be forwarded events for a room it was recently invited to. \ No newline at end of file From b285c9e71668d90013c7eec10838b49d7301622d Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Wed, 28 Oct 2020 12:41:13 +0000 Subject: [PATCH 3/6] Remove type to fix mypy --- synapse/appservice/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/synapse/appservice/__init__.py b/synapse/appservice/__init__.py index f70841ae8613..daee5f52c9dd 100644 --- a/synapse/appservice/__init__.py +++ b/synapse/appservice/__init__.py @@ -19,7 +19,7 @@ from synapse.api.constants import EventTypes from synapse.events import EventBase from synapse.types import GroupID, JsonDict, UserID, get_domain_from_id -from synapse.util.caches.descriptors import _CacheContext, cached +from synapse.util.caches.descriptors import cached if TYPE_CHECKING: from synapse.appservice.api import ApplicationServiceApi @@ -166,7 +166,7 @@ async def _matches_user( @cached(num_args=1, cache_context=True) async def matches_user_in_member_list( - self, room_id: str, store: "DataStore", cache_context: _CacheContext, + self, room_id: str, store: "DataStore", cache_context, ) -> bool: """Check if this service is interested a room based upon it's membership From c7a8f881a130d919db83293637c02361e9f2ba1f Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Wed, 28 Oct 2020 12:54:44 +0000 Subject: [PATCH 4/6] Add `on_invalidate` to the function signature in the hopes that may make things work well --- synapse/appservice/__init__.py | 4 ++-- synapse/storage/databases/main/roommember.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/synapse/appservice/__init__.py b/synapse/appservice/__init__.py index daee5f52c9dd..f70841ae8613 100644 --- a/synapse/appservice/__init__.py +++ b/synapse/appservice/__init__.py @@ -19,7 +19,7 @@ from synapse.api.constants import EventTypes from synapse.events import EventBase from synapse.types import GroupID, JsonDict, UserID, get_domain_from_id -from synapse.util.caches.descriptors import cached +from synapse.util.caches.descriptors import _CacheContext, cached if TYPE_CHECKING: from synapse.appservice.api import ApplicationServiceApi @@ -166,7 +166,7 @@ async def _matches_user( @cached(num_args=1, cache_context=True) async def matches_user_in_member_list( - self, room_id: str, store: "DataStore", cache_context, + self, room_id: str, store: "DataStore", cache_context: _CacheContext, ) -> bool: """Check if this service is interested a room based upon it's membership diff --git a/synapse/storage/databases/main/roommember.py b/synapse/storage/databases/main/roommember.py index 01d9dbb36f44..c59e7cbd06ea 100644 --- a/synapse/storage/databases/main/roommember.py +++ b/synapse/storage/databases/main/roommember.py @@ -145,7 +145,7 @@ def _check_safe_current_state_events_membership_updated_txn(self, txn): ) @cached(max_entries=100000, iterable=True) - async def get_users_in_room(self, room_id: str) -> List[str]: + async def get_users_in_room(self, room_id: str, **kwargs) -> List[str]: return await self.db_pool.runInteraction( "get_users_in_room", self.get_users_in_room_txn, room_id ) From 9ae9a7e1bac47fc2e44e612623d36728ddd514e4 Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Thu, 29 Oct 2020 12:15:41 +0000 Subject: [PATCH 5/6] Remove **kwargs --- synapse/storage/databases/main/roommember.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/synapse/storage/databases/main/roommember.py b/synapse/storage/databases/main/roommember.py index c59e7cbd06ea..01d9dbb36f44 100644 --- a/synapse/storage/databases/main/roommember.py +++ b/synapse/storage/databases/main/roommember.py @@ -145,7 +145,7 @@ def _check_safe_current_state_events_membership_updated_txn(self, txn): ) @cached(max_entries=100000, iterable=True) - async def get_users_in_room(self, room_id: str, **kwargs) -> List[str]: + async def get_users_in_room(self, room_id: str) -> List[str]: return await self.db_pool.runInteraction( "get_users_in_room", self.get_users_in_room_txn, room_id ) From 3d43b2b9a2d35d3a02eafe139abb67739ce418b3 Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Thu, 29 Oct 2020 15:49:08 +0000 Subject: [PATCH 6/6] Update 8676.bugfix --- changelog.d/8676.bugfix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.d/8676.bugfix b/changelog.d/8676.bugfix index 26afb6ef3104..df16c7276181 100644 --- a/changelog.d/8676.bugfix +++ b/changelog.d/8676.bugfix @@ -1 +1 @@ -Fix a bug where an appservice may not be forwarded events for a room it was recently invited to. \ No newline at end of file +Fix a bug where an appservice may not be forwarded events for a room it was recently invited to. Broken in v1.22.0.