Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/18302.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hashes of media files are now tracked by Synapse. Media quarantines will now apply to all files with the same hash.
9 changes: 9 additions & 0 deletions synapse/storage/databases/main/media_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,15 @@ async def get_is_hash_quarantined(self, sha256: str) -> bool:
None if the media_id doesn't exist.
"""

# If we don't have the index yet, performance tanks, so we return False.
# In the background updates, remote_media_cache_sha256_idx is created
# after local_media_repository_sha256_idx, which is why we only need to
# check for the completion of the former.
if not await self.db_pool.updates.has_completed_background_update(
"remote_media_cache_sha256_idx"
):
return False

Comment on lines +1002 to +1010
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I think this is the best we can do. It will add an extra query to each media download, but at least we have short-circuits when all background updates are completed, and if the currently running update is the mentioned one.

def get_matching_media_txn(
txn: LoggingTransaction, table: str, sha256: str
) -> bool:
Expand Down
13 changes: 10 additions & 3 deletions synapse/storage/schema/main/delta/91/01_media_hash.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ ALTER TABLE local_media_repository ADD COLUMN sha256 TEXT;
ALTER TABLE remote_media_cache ADD COLUMN sha256 TEXT;

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