-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Make presence.get_new_events a bit faster #1876
Conversation
We do this by caching the set of users a user shares rooms with.
@@ -280,6 +280,23 @@ def get_rooms_for_user(self, user_id): | |||
user_id, membership_list=[Membership.JOIN], | |||
) | |||
|
|||
@cachedInlineCallbacks(max_entries=50000, cache_context=True, iterable=True) | |||
def get_users_who_share_room_with_user(self, user_id, cache_context): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we are leaking the cache_context.invalidate callbacks if this cache is smaller than the get_users_in_room or get_rooms_for_user caches. I wonder if we need a max_entries at all for dependant caches like this one since it can't be bigger than the get_rooms_for_user or get_users_in_room caches.
synapse/util/caches/descriptors.py
Outdated
@@ -478,6 +478,8 @@ def update_results_dict(res): | |||
|
|||
|
|||
class _CacheContext(namedtuple("_CacheContext", ("cache", "key"))): | |||
# We rely on _CacheContext implementing __eq__ and __hash__ sensibly, | |||
# which namedtuple does for us. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe expound on the nature of the reliance?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I'm worried that future me will find this comment and will have forgotten what bit of code relies on these having __eq__
and __hash__
defined "sensibly" or what sensible means in this case)
Other than the sightly cryptic comment LGTM. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
We do this by caching the set of users a user shares rooms with.