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

Deduplicate membership changes #700

Merged
merged 4 commits into from
Apr 7, 2016
Merged

Conversation

erikjohnston
Copy link
Member

No description provided.

@NegativeMjark
Copy link
Contributor

Is there a reason to only deduplicate joins, or could this be used for all membership changes?

@@ -183,6 +185,44 @@ def update_membership(
third_party_signed=None,
ratelimit=True,
):
if action == Membership.JOIN:
result = self.join_cache.get((room_id, target))
Copy link
Contributor

Choose a reason for hiding this comment

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

Should remote_room_hosts and third_party_signed be part of the request key here?

@erikjohnston erikjohnston force-pushed the erikj/deduplicate_joins branch 3 times, most recently from a4edf78 to 19cecd3 Compare April 7, 2016 10:08
@erikjohnston
Copy link
Member Author

@NegativeMjark PTAL

@NegativeMjark
Copy link
Contributor

LGTM

new_defer = defer.Deferred()
self.key_to_defer[key] = new_defer

def remove_if_current(_):
Copy link
Contributor

Choose a reason for hiding this comment

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

Might not want to throw away the thing passed to the callback.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, I see. This is only ever passed the None from _trigger_defer_manager

Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be clearer to merge the _trigger_defer_manager and the remove_if_current into one thing?

Copy link
Member Author

Choose a reason for hiding this comment

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

Possibly, though I think having them split up makes it clearer what each thing is doing.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think having two functions and an addBoth is less clear in this case.

 @contextmanager
 def manager():
    try:
        yield
     finally:
         d = self.key_to_defer.get(key)
         if d is new_defer:
             self.key_to_defer.pop(key, None)
         d.callback(None)

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, your example doesn't actually work, as we specifically don't hit the callback for the most current defer in the list.

I've changed it though I think it just makes things look more complicated.

@NegativeMjark
Copy link
Contributor

Maybe add a few comments explaining how the thing is supposed to work inside the queue method.


@defer.inlineCallbacks
def queue(self, key):
current_defer = self.key_to_defer.setdefault(key, None)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this setdefault rather than get?

@erikjohnston erikjohnston force-pushed the erikj/deduplicate_joins branch from 19cecd3 to 639cd07 Compare April 7, 2016 13:24
@erikjohnston erikjohnston changed the title Deduplicate joins Deduplicate membership changes Apr 7, 2016

new_defer.addBoth(remove_if_current)

yield current_defer
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this going to have the right log context when it resolves?

@erikjohnston erikjohnston force-pushed the erikj/deduplicate_joins branch from ccc9e70 to ee5aef6 Compare April 7, 2016 14:34
yield
finally:
d.callback(None)
d = self.key_to_defer.get(key)
Copy link
Contributor

Choose a reason for hiding this comment

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

might want to use a different d to avoid confusion.

@NegativeMjark
Copy link
Contributor

LGTM

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