diff options
author | Erik Johnston <erik@matrix.org> | 2018-01-12 16:42:43 +0000 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2018-01-17 10:24:43 +0000 |
commit | 05f98a22249974ce40a461d12da93af0bc624319 (patch) | |
tree | 26c8676ac3532136d810c1dfa0e8802d1ed3c909 /synapse/storage/media_repository.py | |
parent | Merge pull request #2789 from matrix-org/erikj/fix_thumbnails (diff) | |
download | synapse-05f98a22249974ce40a461d12da93af0bc624319.tar.xz |
Keep track of last access time for local media
Diffstat (limited to 'synapse/storage/media_repository.py')
-rw-r--r-- | synapse/storage/media_repository.py | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/synapse/storage/media_repository.py b/synapse/storage/media_repository.py index 6ebc372498..e6cdbb0545 100644 --- a/synapse/storage/media_repository.py +++ b/synapse/storage/media_repository.py @@ -173,7 +173,14 @@ class MediaRepositoryStore(BackgroundUpdateStore): desc="store_cached_remote_media", ) - def update_cached_last_access_time(self, origin_id_tuples, time_ts): + def update_cached_last_access_time(self, local_media, remote_media, time_ms): + """Updates the last access time of the given media + + Args: + local_media (iterable[str]): Set of media_ids + remote_media (iterable[(str, str)]): Set of (server_name, media_id) + time_ms: Current time in milliseconds + """ def update_cache_txn(txn): sql = ( "UPDATE remote_media_cache SET last_access_ts = ?" @@ -181,8 +188,18 @@ class MediaRepositoryStore(BackgroundUpdateStore): ) txn.executemany(sql, ( - (time_ts, media_origin, media_id) - for media_origin, media_id in origin_id_tuples + (time_ms, media_origin, media_id) + for media_origin, media_id in remote_media + )) + + sql = ( + "UPDATE local_media_repository SET last_access_ts = ?" + " WHERE media_id = ?" + ) + + txn.executemany(sql, ( + (time_ms, media_id) + for media_id in local_media )) return self.runInteraction("update_cached_last_access_time", update_cache_txn) |