diff options
author | Erik Johnston <erik@matrix.org> | 2017-05-08 15:32:18 +0100 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2017-05-08 15:32:18 +0100 |
commit | 738ccf61c01df04e1aef521ea7d1ae2844784214 (patch) | |
tree | 0a20f0987044f1666f32a624cd3f0f3037f60fbd /synapse | |
parent | Increase client_ip cache size (diff) | |
download | synapse-738ccf61c01df04e1aef521ea7d1ae2844784214.tar.xz |
Cache check to see if device exists
Diffstat (limited to 'synapse')
-rw-r--r-- | synapse/storage/devices.py | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/synapse/storage/devices.py b/synapse/storage/devices.py index c8d5f5ba8b..fc87c92182 100644 --- a/synapse/storage/devices.py +++ b/synapse/storage/devices.py @@ -18,7 +18,7 @@ import ujson as json from twisted.internet import defer from synapse.api.errors import StoreError -from ._base import SQLBaseStore +from ._base import SQLBaseStore, Cache from synapse.util.caches.descriptors import cached, cachedList, cachedInlineCallbacks @@ -29,6 +29,12 @@ class DeviceStore(SQLBaseStore): def __init__(self, hs): super(DeviceStore, self).__init__(hs) + self.device_id_exists_cache = Cache( + name="device_id_exists", + keylen=2, + max_entries=10000, + ) + self._clock.looping_call( self._prune_old_outbound_device_pokes, 60 * 60 * 1000 ) @@ -54,6 +60,10 @@ class DeviceStore(SQLBaseStore): defer.Deferred: boolean whether the device was inserted or an existing device existed with that ID. """ + key = (user_id, device_id) + if self.device_id_exists_cache.get(key, None): + defer.returnValue(False) + try: inserted = yield self._simple_insert( "devices", @@ -65,6 +75,7 @@ class DeviceStore(SQLBaseStore): desc="store_device", or_ignore=True, ) + self.device_id_exists_cache.prefill(key, True) defer.returnValue(inserted) except Exception as e: logger.error("store_device with device_id=%s(%r) user_id=%s(%r)" |