fix: subscription not updated correctly after rss feed refreshed

* sort the shallow copy of the userIds array so the original array not mutated
This commit is contained in:
Hongbo Wu 2024-03-14 12:56:42 +08:00
parent 3ab9e41b82
commit 1ea09e20bd

View file

@ -43,7 +43,7 @@ export const refreshAllFeeds = async (db: DataSource): Promise<boolean> => {
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,
}