From e7f7d1a573bd88e6d7d7fa5514a6178d91aaea92 Mon Sep 17 00:00:00 2001 From: advplyr Date: Wed, 1 Jan 2025 12:06:01 -0600 Subject: [PATCH] Fix refresh feed when book is deleted and belonged to a series/collection --- server/managers/RssFeedManager.js | 17 ++++++++++------- server/models/Feed.js | 8 ++++---- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/server/managers/RssFeedManager.js b/server/managers/RssFeedManager.js index abfa445f..de009c3d 100644 --- a/server/managers/RssFeedManager.js +++ b/server/managers/RssFeedManager.js @@ -122,7 +122,7 @@ class RssFeedManager { attributes: ['id', 'updatedAt'], include: { model: Database.bookModel, - attributes: ['id', 'updatedAt'], + attributes: ['id', 'audioFiles', 'updatedAt'], through: { attributes: [] }, @@ -133,14 +133,16 @@ class RssFeedManager { } }) + const totalBookTracks = feed.entity.books.reduce((total, book) => total + book.includedAudioFiles.length, 0) + if (feed.feedEpisodes.length !== totalBookTracks) { + return true + } + let newEntityUpdatedAt = feed.entity.updatedAt const mostRecentItemUpdatedAt = feed.entity.books.reduce((mostRecent, book) => { let updatedAt = book.libraryItem.updatedAt > book.updatedAt ? book.libraryItem.updatedAt : book.updatedAt - if (updatedAt > mostRecent) { - return updatedAt - } - return mostRecent + return updatedAt > mostRecent ? updatedAt : mostRecent }, 0) if (mostRecentItemUpdatedAt > newEntityUpdatedAt) { @@ -163,6 +165,9 @@ class RssFeedManager { let feed = await Database.feedModel.findOne({ where: { slug: req.params.slug + }, + include: { + model: Database.feedEpisodeModel } }) if (!feed) { @@ -175,8 +180,6 @@ class RssFeedManager { if (feedRequiresUpdate) { Logger.info(`[RssFeedManager] Feed "${feed.title}" requires update - updating feed`) feed = await feed.updateFeedForEntity() - } else { - feed.feedEpisodes = await feed.getFeedEpisodes() } const xml = feed.buildXml(req.originalHostPrefix) diff --git a/server/models/Feed.js b/server/models/Feed.js index a6ccff22..41bca449 100644 --- a/server/models/Feed.js +++ b/server/models/Feed.js @@ -190,7 +190,8 @@ class Feed extends Model { const booksWithTracks = collectionExpanded.books.filter((book) => book.includedAudioFiles.length) const entityUpdatedAt = booksWithTracks.reduce((mostRecent, book) => { - return book.libraryItem.updatedAt > mostRecent ? book.libraryItem.updatedAt : mostRecent + const updatedAt = book.libraryItem.updatedAt > book.updatedAt ? book.libraryItem.updatedAt : book.updatedAt + return updatedAt > mostRecent ? updatedAt : mostRecent }, collectionExpanded.updatedAt) const firstBookWithCover = booksWithTracks.find((book) => book.coverPath) @@ -278,7 +279,8 @@ class Feed extends Model { static getFeedObjForSeries(userId, seriesExpanded, slug, serverAddress, feedOptions = null) { const booksWithTracks = seriesExpanded.books.filter((book) => book.includedAudioFiles.length) const entityUpdatedAt = booksWithTracks.reduce((mostRecent, book) => { - return book.libraryItem.updatedAt > mostRecent ? book.libraryItem.updatedAt : mostRecent + const updatedAt = book.libraryItem.updatedAt > book.updatedAt ? book.libraryItem.updatedAt : book.updatedAt + return updatedAt > mostRecent ? updatedAt : mostRecent }, seriesExpanded.updatedAt) const firstBookWithCover = booksWithTracks.find((book) => book.coverPath) @@ -475,8 +477,6 @@ class Feed extends Model { /** @type {typeof import('./FeedEpisode')} */ const feedEpisodeModel = this.sequelize.models.feedEpisode - this.feedEpisodes = await this.getFeedEpisodes() - let feedObj = null let feedEpisodeCreateFunc = null let feedEpisodeCreateFuncEntity = null