From 7d357c95f3aee6db54198dc6b0b23e90b4b641fb Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Tue, 31 Mar 2020 08:20:08 -0400 Subject: [PATCH 1/3] Do not try to await None, which can be returned by delete_url_cache. --- synapse/rest/media/v1/preview_url_resource.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/synapse/rest/media/v1/preview_url_resource.py b/synapse/rest/media/v1/preview_url_resource.py index c46676f8fcc8..68ff443ab06a 100644 --- a/synapse/rest/media/v1/preview_url_resource.py +++ b/synapse/rest/media/v1/preview_url_resource.py @@ -427,7 +427,7 @@ async def _expire_url_cache_data(self): except Exception: pass - await self.store.delete_url_cache(removed_media) + await defer.ensureDeferred(self.store.delete_url_cache(removed_media)) if removed_media: logger.info("Deleted %d entries from url cache", len(removed_media)) From c69e7d0bd2c22e413a98ba8ed609f5d40fd577fc Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Tue, 31 Mar 2020 08:31:23 -0400 Subject: [PATCH 2/3] Add a changelog entry. --- changelog.d/7184.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/7184.misc diff --git a/changelog.d/7184.misc b/changelog.d/7184.misc new file mode 100644 index 000000000000..fac5bc04032c --- /dev/null +++ b/changelog.d/7184.misc @@ -0,0 +1 @@ +Convert some of synapse.rest.media to async/await. From 9afe264b0d8e614cdf0bbd80d38a0b96409e5428 Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Tue, 31 Mar 2020 08:44:01 -0400 Subject: [PATCH 3/3] Convert delete_url_cache to async/await. --- synapse/rest/media/v1/preview_url_resource.py | 2 +- synapse/storage/data_stores/main/media_repository.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/synapse/rest/media/v1/preview_url_resource.py b/synapse/rest/media/v1/preview_url_resource.py index 68ff443ab06a..c46676f8fcc8 100644 --- a/synapse/rest/media/v1/preview_url_resource.py +++ b/synapse/rest/media/v1/preview_url_resource.py @@ -427,7 +427,7 @@ async def _expire_url_cache_data(self): except Exception: pass - await defer.ensureDeferred(self.store.delete_url_cache(removed_media)) + await self.store.delete_url_cache(removed_media) if removed_media: logger.info("Deleted %d entries from url cache", len(removed_media)) diff --git a/synapse/storage/data_stores/main/media_repository.py b/synapse/storage/data_stores/main/media_repository.py index 80ca36dedfa9..cf195f8aa61a 100644 --- a/synapse/storage/data_stores/main/media_repository.py +++ b/synapse/storage/data_stores/main/media_repository.py @@ -340,7 +340,7 @@ def _get_expired_url_cache_txn(txn): "get_expired_url_cache", _get_expired_url_cache_txn ) - def delete_url_cache(self, media_ids): + async def delete_url_cache(self, media_ids): if len(media_ids) == 0: return @@ -349,7 +349,7 @@ def delete_url_cache(self, media_ids): def _delete_url_cache_txn(txn): txn.executemany(sql, [(media_id,) for media_id in media_ids]) - return self.db.runInteraction("delete_url_cache", _delete_url_cache_txn) + return await self.db.runInteraction("delete_url_cache", _delete_url_cache_txn) def get_url_cache_media_before(self, before_ts): sql = (