Skip to content

Commit fa53a85

Browse files
authored
Make sure media hashes are not queried until the index is up (#18302)
1 parent fdbcb82 commit fa53a85

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

changelog.d/18302.feature

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hashes of media files are now tracked by Synapse. Media quarantines will now apply to all files with the same hash.

synapse/storage/databases/main/media_repository.py

+9
Original file line numberDiff line numberDiff line change
@@ -999,6 +999,15 @@ async def get_is_hash_quarantined(self, sha256: str) -> bool:
999999
None if the media_id doesn't exist.
10001000
"""
10011001

1002+
# If we don't have the index yet, performance tanks, so we return False.
1003+
# In the background updates, remote_media_cache_sha256_idx is created
1004+
# after local_media_repository_sha256_idx, which is why we only need to
1005+
# check for the completion of the former.
1006+
if not await self.db_pool.updates.has_completed_background_update(
1007+
"remote_media_cache_sha256_idx"
1008+
):
1009+
return False
1010+
10021011
def get_matching_media_txn(
10031012
txn: LoggingTransaction, table: str, sha256: str
10041013
) -> bool:

synapse/storage/schema/main/delta/91/01_media_hash.sql

+10-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ ALTER TABLE local_media_repository ADD COLUMN sha256 TEXT;
1616
ALTER TABLE remote_media_cache ADD COLUMN sha256 TEXT;
1717

1818
-- Add a background updates to handle creating the new index.
19-
INSERT INTO background_updates (ordering, update_name, progress_json) VALUES
20-
(9101, 'local_media_repository_sha256_idx', '{}'),
21-
(9101, 'remote_media_cache_sha256_idx', '{}');
19+
--
20+
-- Note that the ordering of the update is not following the usual scheme. This
21+
-- is because when upgrading from Synapse 1.127, this index is fairly important
22+
-- to have up quickly, so that it doesn't tank performance, which is why it is
23+
-- scheduled before other background updates in the 1.127 -> 1.128 upgrade
24+
INSERT INTO
25+
background_updates (ordering, update_name, progress_json)
26+
VALUES
27+
(8890, 'local_media_repository_sha256_idx', '{}'),
28+
(8891, 'remote_media_cache_sha256_idx', '{}');

0 commit comments

Comments
 (0)