Dedupe KeyedEdu and Devices federation repl traffic

This commit is contained in:
Erik Johnston 2017-04-10 16:49:51 +01:00
parent 2e6f5a4910
commit 40453b3f84

View File

@ -267,9 +267,12 @@ class FederationRemoteSendQueue(object):
keys = self.keyed_edu_changed.keys()
i = keys.bisect_right(from_token)
j = keys.bisect_right(to_token) + 1
keyed_edus = set((k, self.keyed_edu_changed[k]) for k in keys[i:j])
# We purposefully clobber based on the key here, python dict comprehensions
# always use the last value, so this will correctly point to the last
# stream position.
keyed_edus = {self.keyed_edu_changed[k]: k for k in keys[i:j]}
for (pos, (destination, edu_key)) in keyed_edus:
for ((destination, edu_key), pos) in keyed_edus.iteritems():
rows.append((pos, KeyedEduRow(
key=edu_key,
edu=self.keyed_edu[(destination, edu_key)],
@ -279,7 +282,7 @@ class FederationRemoteSendQueue(object):
keys = self.edus.keys()
i = keys.bisect_right(from_token)
j = keys.bisect_right(to_token) + 1
edus = set((k, self.edus[k]) for k in keys[i:j])
edus = [(k, self.edus[k]) for k in keys[i:j]]
for (pos, edu) in edus:
rows.append((pos, EduRow(edu)))
@ -288,7 +291,7 @@ class FederationRemoteSendQueue(object):
keys = self.failures.keys()
i = keys.bisect_right(from_token)
j = keys.bisect_right(to_token) + 1
failures = set((k, self.failures[k]) for k in keys[i:j])
failures = [(k, self.failures[k]) for k in keys[i:j]]
for (pos, (destination, failure)) in failures:
rows.append((pos, FailureRow(
@ -300,9 +303,9 @@ class FederationRemoteSendQueue(object):
keys = self.device_messages.keys()
i = keys.bisect_right(from_token)
j = keys.bisect_right(to_token) + 1
device_messages = set((k, self.device_messages[k]) for k in keys[i:j])
device_messages = {self.device_messages[k]: k for k in keys[i:j]}
for (pos, destination) in device_messages:
for (destination, pos) in device_messages.iteritems():
rows.append((pos, DeviceRow(
destination=destination,
)))