summary refs log tree commit diff
path: root/synapse/storage/_base.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2015-08-04 09:32:23 +0100
committerErik Johnston <erik@matrix.org>2015-08-04 09:32:23 +0100
commit4d6cb8814e134eba644afeed7bd49df0c7951342 (patch)
treef6d14b56fd5ec6691eb95f0c160b632b64dd192c /synapse/storage/_base.py
parentMerge pull request #210 from matrix-org/reg-v2a-password-skip (diff)
downloadsynapse-4d6cb8814e134eba644afeed7bd49df0c7951342.tar.xz
Speed up event filtering (for ACL) logic
Diffstat (limited to 'synapse/storage/_base.py')
-rw-r--r--synapse/storage/_base.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/synapse/storage/_base.py b/synapse/storage/_base.py
index 8f812f0fd7..7b76ee3b73 100644
--- a/synapse/storage/_base.py
+++ b/synapse/storage/_base.py
@@ -71,6 +71,11 @@ class Cache(object):
         self.thread = None
         caches_by_name[name] = self.cache
 
+        class Sentinel(object):
+            __slots__ = []
+
+        self.sentinel = Sentinel()
+
     def check_thread(self):
         expected_thread = self.thread
         if expected_thread is None:
@@ -85,9 +90,10 @@ class Cache(object):
         if len(keyargs) != self.keylen:
             raise ValueError("Expected a key to have %d items", self.keylen)
 
-        if keyargs in self.cache:
+        val = self.cache.get(keyargs, self.sentinel)
+        if val is not self.sentinel:
             cache_counter.inc_hits(self.name)
-            return self.cache[keyargs]
+            return val
 
         cache_counter.inc_misses(self.name)
         raise KeyError()