Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2202 from matrix-org/erikj/cache_count_device
Browse files Browse the repository at this point in the history
Cache one time key counts
  • Loading branch information
erikjohnston authored May 8, 2017
2 parents dcabef9 + 8571f86 commit b9c84f3
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions synapse/storage/end_to_end_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from twisted.internet import defer

from synapse.api.errors import SynapseError
from synapse.util.caches.descriptors import cached

from canonicaljson import encode_canonical_json
import ujson as json
Expand Down Expand Up @@ -177,10 +178,14 @@ def _add_e2e_one_time_keys(txn):
for algorithm, key_id, json_bytes in new_keys
],
)
txn.call_after(
self.count_e2e_one_time_keys.invalidate, (user_id, device_id,)
)
yield self.runInteraction(
"add_e2e_one_time_keys_insert", _add_e2e_one_time_keys
)

@cached(max_entries=10000)
def count_e2e_one_time_keys(self, user_id, device_id):
""" Count the number of one time keys the server has for a device
Returns:
Expand Down Expand Up @@ -225,6 +230,9 @@ def _claim_e2e_one_time_keys(txn):
)
for user_id, device_id, algorithm, key_id in delete:
txn.execute(sql, (user_id, device_id, algorithm, key_id))
txn.call_after(
self.count_e2e_one_time_keys.invalidate, (user_id, device_id,)
)
return result
return self.runInteraction(
"claim_e2e_one_time_keys", _claim_e2e_one_time_keys
Expand All @@ -242,3 +250,4 @@ def delete_e2e_keys_by_device(self, user_id, device_id):
keyvalues={"user_id": user_id, "device_id": device_id},
desc="delete_e2e_one_time_keys_by_device"
)
self.count_e2e_one_time_keys.invalidate((user_id, device_id,))

0 comments on commit b9c84f3

Please sign in to comment.