Fix notifiying about old "new" streams

Add tests for `FeedDAO.unlinkStreamsOlderThan(:offsetDateTime) `
Closes #10237
This commit is contained in:
TobiGr 2023-10-14 18:31:33 +02:00
parent 6f51c47dc9
commit 5265b767cb
2 changed files with 144 additions and 10 deletions

View file

@ -93,18 +93,28 @@ abstract class FeedDAO {
uploadDateBefore: OffsetDateTime?
): Maybe<List<StreamWithState>>
/**
* Remove links to streams that are older than the given date
* **but keep at least one stream per uploader**.
*
* One stream per uploader is kept because it is needed as reference
* when fetching new streams to check if they are new or not.
* @param offsetDateTime the newest date to keep, older streams are removed
*/
@Query(
"""
DELETE FROM feed WHERE
feed.stream_id IN (
SELECT s.uid FROM streams s
INNER JOIN feed f
ON s.uid = f.stream_id
WHERE s.upload_date < :offsetDateTime
)
DELETE FROM feed
WHERE feed.stream_id IN (SELECT uid from (
SELECT s.uid,
(SELECT MAX(upload_date)
FROM streams
WHERE uploader_url = s.uploader_url) max_upload_date
FROM streams s
INNER JOIN feed f
ON s.uid = f.stream_id
WHERE s.upload_date < :offsetDateTime
AND s.upload_date <> max_upload_date))
"""
)
abstract fun unlinkStreamsOlderThan(offsetDateTime: OffsetDateTime)