summary refs log tree commit diff
path: root/synapse/storage
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2016-09-15 14:27:15 +0100
committerErik Johnston <erik@matrix.org>2016-09-15 14:28:13 +0100
commitcb3edec6af55efb126f5e7ee66c4d895ef35a66e (patch)
treea80740335d559f06a7568aa633b7ac78ac2e0e00 /synapse/storage
parentAdd cache to get_forward_extremeties_for_room (diff)
downloadsynapse-cb3edec6af55efb126f5e7ee66c4d895ef35a66e.tar.xz
Use stream_change cache to make get_forward_extremeties_for_room cache more effective
Diffstat (limited to 'synapse/storage')
-rw-r--r--synapse/storage/event_federation.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/synapse/storage/event_federation.py b/synapse/storage/event_federation.py
index 050b78d652..97d0c26475 100644
--- a/synapse/storage/event_federation.py
+++ b/synapse/storage/event_federation.py
@@ -344,8 +344,17 @@ class EventFederationStore(SQLBaseStore):
                 self.get_latest_event_ids_in_room.invalidate, (room_id,)
             )
 
-    @cached(max_entries=5000, num_args=2)
     def get_forward_extremeties_for_room(self, room_id, stream_ordering):
+        # We want to make the cache more effective, so we clamp to the last
+        # change before the given ordering.
+        last_change = self._events_stream_cache.get_pos_of_last_change(room_id)
+        if last_change:
+            stream_ordering = min(last_change, stream_ordering)
+
+        return self._get_forward_extremeties_for_room(room_id, stream_ordering)
+
+    @cached(max_entries=5000, num_args=2)
+    def _get_forward_extremeties_for_room(self, room_id, stream_ordering):
         """For a given room_id and stream_ordering, return the forward
         extremeties of the room at that point in "time".