summary refs log tree commit diff
diff options
context:
space:
mode:
authorErik Johnston <erikj@jki.re>2018-07-24 13:39:58 +0100
committerGitHub <noreply@github.com>2018-07-24 13:39:58 +0100
commit0a8e4f3af9db60c28356483236ecdf4500fa8ce2 (patch)
tree385db0eb20a05b9d0f6b7ce181cc2e2253c24241
parentMerge pull request #3591 from matrix-org/rav/logcontext_fixes (diff)
parentMerge branch 'develop' of github.com:matrix-org/synapse into erikj/speed_up_c... (diff)
downloadsynapse-0a8e4f3af9db60c28356483236ecdf4500fa8ce2.tar.xz
Merge pull request #3592 from matrix-org/erikj/speed_up_calculate_state_delta
Speed up _calculate_state_delta
-rw-r--r--changelog.d/3592.misc1
-rw-r--r--synapse/storage/events.py16
2 files changed, 5 insertions, 12 deletions
diff --git a/changelog.d/3592.misc b/changelog.d/3592.misc
new file mode 100644
index 0000000000..60129569c2
--- /dev/null
+++ b/changelog.d/3592.misc
@@ -0,0 +1 @@
+Speed up calculating state deltas in persist_event loop
diff --git a/synapse/storage/events.py b/synapse/storage/events.py
index 4d0706f23d..19c05dc8d6 100644
--- a/synapse/storage/events.py
+++ b/synapse/storage/events.py
@@ -439,8 +439,7 @@ class EventsStore(EventsWorkerStore):
                                     delta = yield self._calculate_state_delta(
                                         room_id, current_state,
                                     )
-                                    if delta is not None:
-                                        state_delta_for_room[room_id] = delta
+                                    state_delta_for_room[room_id] = delta
 
                 yield self.runInteraction(
                     "persist_events",
@@ -655,21 +654,14 @@ class EventsStore(EventsWorkerStore):
         """
         existing_state = yield self.get_current_state_ids(room_id)
 
-        existing_events = set(itervalues(existing_state))
-        new_events = set(ev_id for ev_id in itervalues(current_state))
-        changed_events = existing_events ^ new_events
-
-        if not changed_events:
-            return
-
         to_delete = {
             key: ev_id for key, ev_id in iteritems(existing_state)
-            if ev_id in changed_events
+            if ev_id != current_state.get(key)
         }
-        events_to_insert = (new_events - existing_events)
+
         to_insert = {
             key: ev_id for key, ev_id in iteritems(current_state)
-            if ev_id in events_to_insert
+            if ev_id != existing_state.get(key)
         }
 
         defer.returnValue((to_delete, to_insert))