From 49f4bc470993136ee4f5af7c34bee5ddc22768bd Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Mon, 27 Feb 2017 18:33:41 +0000 Subject: 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. --- synapse/storage/events.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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 ) -- cgit 1.4.1 From c0d6045776909a83181a4a925198c58e625ea4a2 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Mon, 27 Feb 2017 18:45:24 +0000 Subject: It should be all --- synapse/storage/events.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/synapse/storage/events.py b/synapse/storage/events.py index a4ce71cb27..08807deba9 100644 --- a/synapse/storage/events.py +++ b/synapse/storage/events.py @@ -316,7 +316,7 @@ class EventsStore(SQLBaseStore): and len(new_latest_event_ids) == 1 ) if len_1: - all_single_prev_not_state = any( + all_single_prev_not_state = all( len(event.prev_events) == 1 and not event.is_state() for event, ctx in ev_ctx_rm -- cgit 1.4.1 From a41dce8f8ae8bfb957a5830783e00437b4636c10 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Mon, 27 Feb 2017 18:54:43 +0000 Subject: Remove needless check --- synapse/storage/events.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/synapse/storage/events.py b/synapse/storage/events.py index 08807deba9..db01eb6d14 100644 --- a/synapse/storage/events.py +++ b/synapse/storage/events.py @@ -320,8 +320,6 @@ class EventsStore(SQLBaseStore): 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. -- cgit 1.4.1