run prune trash job at 3am UTC daily

This commit is contained in:
Hongbo Wu
2024-06-12 19:27:42 +08:00
parent 46aa405552
commit 71d07caf94
7 changed files with 28 additions and 19 deletions

View File

@ -4,9 +4,7 @@
BEGIN;
CREATE OR REPLACE PROCEDURE batch_delete_trash_items(
minimum_items INT
)
CREATE OR REPLACE PROCEDURE omnivore.batch_delete_trash_items()
RETURNS VOID AS $$
DECLARE
user_record RECORD;
@ -24,25 +22,11 @@ BEGIN
-- For Row Level Security
PERFORM omnivore.set_claims(user_record.id, 'omnivore_user');
-- keep the minimum number of items in trash
DELETE FROM omnivore.library_item
WHERE
user_id = user_record.id
AND state = 'DELETED'
AND deleted_at < NOW() - INTERVAL '14 days'
AND id NOT IN (
SELECT
id
FROM
omnivore.library_item
WHERE
user_id = user_record.id
AND state = 'DELETED'
AND deleted_at < NOW() - INTERVAL '14 days'
ORDER BY
deleted_at DESC
LIMIT minimum_items
);
AND deleted_at < NOW() - INTERVAL '14 days';
COMMIT;
END LOOP;

View File

@ -4,6 +4,6 @@
BEGIN;
DROP PROCEDURE IF EXISTS batch_delete_trash_items();
DROP PROCEDURE IF EXISTS omnivore.batch_delete_trash_items();
COMMIT;