summary refs log tree commit diff
path: root/synapse/storage/events.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2017-02-27 18:33:41 +0000
committerErik Johnston <erik@matrix.org>2017-02-27 18:33:41 +0000
commit49f4bc470993136ee4f5af7c34bee5ddc22768bd (patch)
tree1b7777c0f8774363a888078343cb0fd52239b82d /synapse/storage/events.py
parentMerge pull request #1904 from Pneumaticat/patch-1 (diff)
downloadsynapse-49f4bc470993136ee4f5af7c34bee5ddc22768bd.tar.xz
Don't fetch current state in common case
Currently we fetch the list of current state events whenever we send
something in a room. This is overkill for the common case of persisting
a simple chain of non-state events, so lets handle that case specially.
Diffstat (limited to 'synapse/storage/events.py')
-rw-r--r--synapse/storage/events.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/synapse/storage/events.py b/synapse/storage/events.py
index c88f689d3a..a4ce71cb27 100644
--- a/synapse/storage/events.py
+++ b/synapse/storage/events.py
@@ -311,6 +311,23 @@ class EventsStore(SQLBaseStore):
 
                             new_forward_extremeties[room_id] = new_latest_event_ids
 
+                            len_1 = (
+                                len(latest_event_ids) == 1
+                                and len(new_latest_event_ids) == 1
+                            )
+                            if len_1:
+                                all_single_prev_not_state = any(
+                                    len(event.prev_events) == 1
+                                    and not event.is_state()
+                                    for event, ctx in ev_ctx_rm
+                                    if not event.internal_metadata.is_outlier()
+                                    and not ctx.rejected
+                                )
+                                # Don't bother calculating state if they're just
+                                # a long chain of single ancestor non-state events.
+                                if all_single_prev_not_state:
+                                    continue
+
                             state = yield self._calculate_state_delta(
                                 room_id, ev_ctx_rm, new_latest_event_ids
                             )