summary refs log tree commit diff
path: root/synapse/storage/_base.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2017-01-10 14:34:50 +0000
committerErik Johnston <erik@matrix.org>2017-01-10 14:34:50 +0000
commitdd52d4de4c9318b377a880b2662124688fc23129 (patch)
tree12929878d1b66312bb1a8a6ae11dce50a3869921 /synapse/storage/_base.py
parentMerge branch 'master' of github.com:matrix-org/synapse into develop (diff)
downloadsynapse-dd52d4de4c9318b377a880b2662124688fc23129.tar.xz
Limit number of entries to prefill from cache
Some tables, like device_inbox, take a long time to query at startup for
the stream change cache prefills. This is likely because they are slower
growing streams and so are more fragmented on disk. For now, lets pull
fewer entries out to make startup quicker.

In future, we should add a better index to make it even faster.
Diffstat (limited to 'synapse/storage/_base.py')
-rw-r--r--synapse/storage/_base.py5
1 files changed, 3 insertions, 2 deletions
diff --git a/synapse/storage/_base.py b/synapse/storage/_base.py
index b62c459d8b..5620a655eb 100644
--- a/synapse/storage/_base.py
+++ b/synapse/storage/_base.py
@@ -838,18 +838,19 @@ class SQLBaseStore(object):
         return txn.execute(sql, keyvalues.values())
 
     def _get_cache_dict(self, db_conn, table, entity_column, stream_column,
-                        max_value):
+                        max_value, limit=100000):
         # Fetch a mapping of room_id -> max stream position for "recent" rooms.
         # It doesn't really matter how many we get, the StreamChangeCache will
         # do the right thing to ensure it respects the max size of cache.
         sql = (
             "SELECT %(entity)s, MAX(%(stream)s) FROM %(table)s"
-            " WHERE %(stream)s > ? - 100000"
+            " WHERE %(stream)s > ? - %(limit)s"
             " GROUP BY %(entity)s"
         ) % {
             "table": table,
             "entity": entity_column,
             "stream": stream_column,
+            "limit": limit,
         }
 
         sql = self.database_engine.convert_param_style(sql)