From 1ea09e20bd81f6feed9636ef3415ad1066c84729 Mon Sep 17 00:00:00 2001 From: Hongbo Wu Date: Thu, 14 Mar 2024 12:56:42 +0800 Subject: [PATCH] fix: subscription not updated correctly after rss feed refreshed * sort the shallow copy of the userIds array so the original array not mutated --- packages/api/src/jobs/rss/refreshAllFeeds.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/api/src/jobs/rss/refreshAllFeeds.ts b/packages/api/src/jobs/rss/refreshAllFeeds.ts index d68263400..8d49b6096 100644 --- a/packages/api/src/jobs/rss/refreshAllFeeds.ts +++ b/packages/api/src/jobs/rss/refreshAllFeeds.ts @@ -43,7 +43,7 @@ export const refreshAllFeeds = async (db: DataSource): Promise => { AND (s.scheduled_at <= NOW() OR s.scheduled_at IS NULL) AND u.status = $4 GROUP BY - s.url + url `, ['RSS', 'ACTIVE', 'following', 'ACTIVE'] )) as RssSubscriptionGroup[] @@ -76,7 +76,10 @@ const updateSubscriptionGroup = async ( refreshContext: RSSRefreshContext ) => { let feedURL = group.url - const userList = JSON.stringify(group.userIds.sort()) + const userIds = group.userIds + // sort the user ids so that the job id is consistent + // [...userIds] creates a shallow copy, so sort() does not mutate the original + const userList = JSON.stringify([...userIds].sort()) if (!feedURL) { logger.error('no url for feed group', group) return @@ -105,7 +108,7 @@ const updateSubscriptionGroup = async ( scheduledTimestamps: group.scheduledDates.map((timestamp) => timestamp.getTime() ), // unix timestamp in milliseconds - userIds: group.userIds, + userIds, fetchContentTypes: group.fetchContentTypes, folders: group.folders, }