mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-02 12:26:02 -04:00
Cache tags and account data
This commit is contained in:
parent
c23a8c7833
commit
00cb3eb24b
7 changed files with 137 additions and 102 deletions
|
@ -14,6 +14,7 @@
|
|||
# limitations under the License.
|
||||
|
||||
from ._base import SQLBaseStore
|
||||
from synapse.util.caches.stream_change_cache import StreamChangeCache
|
||||
from twisted.internet import defer
|
||||
|
||||
import ujson as json
|
||||
|
@ -23,6 +24,13 @@ logger = logging.getLogger(__name__)
|
|||
|
||||
|
||||
class AccountDataStore(SQLBaseStore):
|
||||
def __init__(self, hs):
|
||||
super(AccountDataStore, self).__init__(hs)
|
||||
|
||||
self._account_data_stream_cache = StreamChangeCache(
|
||||
"AccountDataChangeCache", self._account_data_id_gen.get_max_token(None),
|
||||
max_size=1000,
|
||||
)
|
||||
|
||||
def get_account_data_for_user(self, user_id):
|
||||
"""Get all the client account_data for a user.
|
||||
|
@ -83,7 +91,7 @@ class AccountDataStore(SQLBaseStore):
|
|||
"get_account_data_for_room", get_account_data_for_room_txn
|
||||
)
|
||||
|
||||
def get_updated_account_data_for_user(self, user_id, stream_id):
|
||||
def get_updated_account_data_for_user(self, user_id, stream_id, room_ids=None):
|
||||
"""Get all the client account_data for a that's changed.
|
||||
|
||||
Args:
|
||||
|
@ -120,6 +128,12 @@ class AccountDataStore(SQLBaseStore):
|
|||
|
||||
return (global_account_data, account_data_by_room)
|
||||
|
||||
changed = self._account_data_stream_cache.get_entity_has_changed(
|
||||
user_id, int(stream_id)
|
||||
)
|
||||
if not changed:
|
||||
defer.returnValue(({}, {}))
|
||||
|
||||
return self.runInteraction(
|
||||
"get_updated_account_data_for_user", get_updated_account_data_for_user_txn
|
||||
)
|
||||
|
@ -186,6 +200,10 @@ class AccountDataStore(SQLBaseStore):
|
|||
"content": content_json,
|
||||
}
|
||||
)
|
||||
txn.call_after(
|
||||
self._account_data_stream_cache.entity_has_changed,
|
||||
user_id, next_id,
|
||||
)
|
||||
self._update_max_stream_id(txn, next_id)
|
||||
|
||||
with (yield self._account_data_id_gen.get_next(self)) as next_id:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue