summary refs log tree commit diff
path: root/synapse/appservice
diff options
context:
space:
mode:
authorEric Eastwood <erice@element.io>2022-10-27 13:29:23 -0500
committerGitHub <noreply@github.com>2022-10-27 18:29:23 +0000
commitaa70556699e649f46f51a198fb104eecdc0d311b (patch)
treea1ff5b0f46480e516786d98a59451baa7a5b528a /synapse/appservice
parentFix tests for change in PostgreSQL 14 behavior change. (#14310) (diff)
downloadsynapse-aa70556699e649f46f51a198fb104eecdc0d311b.tar.xz
Check appservice user interest against the local users instead of all users (`get_users_in_room` mis-use) (#13958)
Diffstat (limited to 'synapse/appservice')
-rw-r--r--synapse/appservice/__init__.py16
1 files changed, 14 insertions, 2 deletions
diff --git a/synapse/appservice/__init__.py b/synapse/appservice/__init__.py
index 0dfa00df44..500bdde3a9 100644
--- a/synapse/appservice/__init__.py
+++ b/synapse/appservice/__init__.py
@@ -172,12 +172,24 @@ class ApplicationService:
         Returns:
             True if this service would like to know about this room.
         """
-        member_list = await store.get_users_in_room(
+        # We can use `get_local_users_in_room(...)` here because an application service
+        # can only be interested in local users of the server it's on (ignore any remote
+        # users that might match the user namespace regex).
+        #
+        # In the future, we can consider re-using
+        # `store.get_app_service_users_in_room` which is very similar to this
+        # function but has a slightly worse performance than this because we
+        # have an early escape-hatch if we find a single user that the
+        # appservice is interested in. The juice would be worth the squeeze if
+        # `store.get_app_service_users_in_room` was used in more places besides
+        # an experimental MSC. But for now we can avoid doing more work and
+        # barely using it later.
+        local_user_ids = await store.get_local_users_in_room(
             room_id, on_invalidate=cache_context.invalidate
         )
 
         # check joined member events
-        for user_id in member_list:
+        for user_id in local_user_ids:
             if self.is_interested_in_user(user_id):
                 return True
         return False