diff options
author | Erik Johnston <erik@matrix.org> | 2016-06-29 14:57:59 +0100 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2016-06-29 14:57:59 +0100 |
commit | a70688445dd7a9fa41a55a642fb9a394f291ae45 (patch) | |
tree | 780be0bce7d1f48decb341bd665237435b992bda /synapse/storage | |
parent | Track approximate last access time for remote media (diff) | |
download | synapse-a70688445dd7a9fa41a55a642fb9a394f291ae45.tar.xz |
Implement purge_media_cache admin API
Diffstat (limited to 'synapse/storage')
-rw-r--r-- | synapse/storage/media_repository.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/synapse/storage/media_repository.py b/synapse/storage/media_repository.py index 44e4d38307..4c0f82353d 100644 --- a/synapse/storage/media_repository.py +++ b/synapse/storage/media_repository.py @@ -205,3 +205,32 @@ class MediaRepositoryStore(SQLBaseStore): }, desc="store_remote_media_thumbnail", ) + + def get_remote_media_before(self, before_ts): + sql = ( + "SELECT media_origin, media_id, filesystem_id" + " FROM remote_media_cache" + " WHERE last_access_ts < ?" + ) + + return self._execute( + "get_remote_media_before", self.cursor_to_dict, sql, before_ts + ) + + def delete_remote_media(self, media_origin, media_id): + def delete_remote_media_txn(txn): + self._simple_delete_txn( + txn, + "remote_media_cache", + keyvalues={ + "media_origin": media_origin, "media_id": media_id + }, + ) + self._simple_delete_txn( + txn, + "remote_media_cache_thumbnails", + keyvalues={ + "media_origin": media_origin, "media_id": media_id + }, + ) + return self.runInteraction("delete_remote_media", delete_remote_media_txn) |