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

Make presence.get_new_events a bit faster #1876

Merged
merged 5 commits into from
Feb 2, 2017

Conversation

erikjohnston
Copy link
Member

We do this by caching the set of users a user shares rooms with.

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):
Copy link
Contributor

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.

@@ -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.
Copy link
Contributor

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?

Copy link
Contributor

@NegativeMjark NegativeMjark Feb 2, 2017

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)

@NegativeMjark
Copy link
Contributor

Other than the sightly cryptic comment LGTM.

Copy link
Contributor

@NegativeMjark NegativeMjark left a comment

Choose a reason for hiding this comment

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

LGTM

@erikjohnston erikjohnston merged commit a833189 into develop Feb 2, 2017
@erikjohnston erikjohnston deleted the erikj/shared_member_store branch March 29, 2017 10:58
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants