mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
update sql to deduplicate rss subscriptions
This commit is contained in:
parent
eb667e04b9
commit
6e79f6c67f
2 changed files with 2 additions and 4 deletions
|
|
@ -185,7 +185,6 @@ export const subscribeResolver = authorized<
|
|||
url: input.url || undefined,
|
||||
name: input.name || undefined,
|
||||
user: { id: uid },
|
||||
status: SubscriptionStatus.Active,
|
||||
type: input.subscriptionType || SubscriptionType.Rss, // default to rss
|
||||
})
|
||||
)
|
||||
|
|
|
|||
|
|
@ -6,13 +6,12 @@ BEGIN;
|
|||
|
||||
-- Deleting duplicates first to avoid unique constraint violation
|
||||
WITH DuplicateCTE AS (
|
||||
SELECT user_id, url,
|
||||
ROW_NUMBER() OVER (PARTITION BY user_id, url ORDER BY (SELECT NULL)) AS RowNum
|
||||
SELECT id, ROW_NUMBER() OVER (PARTITION BY user_id, url ORDER BY status, last_fetched_at DESC NULLS LAST) AS row_number
|
||||
FROM omnivore.subscriptions
|
||||
WHERE type = 'RSS'
|
||||
)
|
||||
DELETE FROM omnivore.subscriptions
|
||||
WHERE (user_id, url) IN (SELECT user_id, url FROM DuplicateCTE WHERE RowNum > 1);
|
||||
WHERE id IN (SELECT id FROM DuplicateCTE WHERE row_number > 1);
|
||||
|
||||
ALTER TABLE omnivore.subscriptions ADD CONSTRAINT subscriptions_user_id_url_key UNIQUE (user_id, url);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue