Skip to content
Snippets Groups Projects
Unverified Commit 145cb68c authored by Travis Ralston's avatar Travis Ralston Committed by GitHub
Browse files

Check if excluded domains array is empty (#574)

`m.origin <> ANY(array[]:text[])` doesn't seem to work (or matches zero records). We need to check if the array is empty using `cardinality`. In testing, `array_length` didn't work, and since we're only ever using a one dimensional array, cardinality is fine.

Fixes https://github.com/t2bot/matrix-media-repo/issues/564
parent 5ec24128
No related branches found
No related tags found
No related merge requests found
......@@ -16,6 +16,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
* Metrics for redirected and HTML requests are tracked.
* Fixed more issues relating to non-dimensional media being thumbnailed (`invalid image size: 0x0` errors).
* Long-running purge requests no longer fail when the requesting client times out. They are continued in the background.
* Purging old media has been fixed to actually identify old media.
## [1.3.4] - February 9, 2024
......
......@@ -43,7 +43,7 @@ const selectMediaByLocationExists = "SELECT TRUE FROM media WHERE datastore_id =
const selectMediaByUserCount = "SELECT COUNT(*) FROM media WHERE user_id = $1;"
const selectMediaByOriginAndUserIds = "SELECT origin, media_id, upload_name, content_type, user_id, sha256_hash, size_bytes, creation_ts, quarantined, datastore_id, location FROM media WHERE origin = $1 AND user_id = ANY($2);"
const selectMediaByOriginAndIds = "SELECT origin, media_id, upload_name, content_type, user_id, sha256_hash, size_bytes, creation_ts, quarantined, datastore_id, location FROM media WHERE origin = $1 AND media_id = ANY($2);"
const selectOldMediaExcludingDomains = "SELECT m.origin, m.media_id, m.upload_name, m.content_type, m.user_id, m.sha256_hash, m.size_bytes, m.creation_ts, m.quarantined, m.datastore_id, m.location FROM media AS m WHERE m.origin <> ANY($1) AND m.creation_ts < $2 AND (SELECT COUNT(d.*) FROM media AS d WHERE d.sha256_hash = m.sha256_hash AND d.creation_ts >= $2) = 0 AND (SELECT COUNT(d.*) FROM media AS d WHERE d.sha256_hash = m.sha256_hash AND d.origin = ANY($1)) = 0;"
const selectOldMediaExcludingDomains = "SELECT m.origin, m.media_id, m.upload_name, m.content_type, m.user_id, m.sha256_hash, m.size_bytes, m.creation_ts, m.quarantined, m.datastore_id, m.location FROM media AS m WHERE (m.origin <> ANY($1) OR CARDINALITY($1) = 0) AND m.creation_ts < $2 AND (SELECT COUNT(d.*) FROM media AS d WHERE d.sha256_hash = m.sha256_hash AND d.creation_ts >= $2) = 0 AND (SELECT COUNT(d.*) FROM media AS d WHERE d.sha256_hash = m.sha256_hash AND d.origin = ANY($1)) = 0;"
const deleteMedia = "DELETE FROM media WHERE origin = $1 AND media_id = $2;"
const updateMediaLocation = "UPDATE media SET datastore_id = $3, location = $4 WHERE datastore_id = $1 AND location = $2;"
const selectMediaByLocation = "SELECT origin, media_id, upload_name, content_type, user_id, sha256_hash, size_bytes, creation_ts, quarantined, datastore_id, location FROM media WHERE datastore_id = $1 AND location = $2;"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment