diff --git a/server/controllers/LibraryItemController.js b/server/controllers/LibraryItemController.js index ca2c1b00..fc8ca1cf 100644 --- a/server/controllers/LibraryItemController.js +++ b/server/controllers/LibraryItemController.js @@ -52,7 +52,7 @@ class LibraryItemController { await this.cacheManager.purgeCoverCache(libraryItem.id) } - var hasUpdates = libraryItem.update(req.body) + const hasUpdates = libraryItem.update(req.body) if (hasUpdates) { Logger.debug(`[LibraryItemController] Updated now saving`) await this.db.updateLibraryItem(libraryItem) @@ -70,8 +70,8 @@ class LibraryItemController { // PATCH: will create new authors & series if in payload // async updateMedia(req, res) { - var libraryItem = req.libraryItem - var mediaPayload = req.body + const libraryItem = req.libraryItem + const mediaPayload = req.body // Item has cover and update is removing cover so purge it from cache if (libraryItem.media.coverPath && (mediaPayload.coverPath === '' || mediaPayload.coverPath === null)) { await this.cacheManager.purgeCoverCache(libraryItem.id) @@ -83,7 +83,7 @@ class LibraryItemController { } // Podcast specific - var isPodcastAutoDownloadUpdated = false + let isPodcastAutoDownloadUpdated = false if (libraryItem.isPodcast) { if (mediaPayload.autoDownloadEpisodes !== undefined && libraryItem.media.autoDownloadEpisodes !== mediaPayload.autoDownloadEpisodes) { isPodcastAutoDownloadUpdated = true @@ -92,8 +92,10 @@ class LibraryItemController { } } - var hasUpdates = libraryItem.media.update(mediaPayload) + const hasUpdates = libraryItem.media.update(mediaPayload) if (hasUpdates) { + libraryItem.updatedAt = Date.now() + if (isPodcastAutoDownloadUpdated) { this.cronManager.checkUpdatePodcastCron(libraryItem) } diff --git a/server/managers/RssFeedManager.js b/server/managers/RssFeedManager.js index 3790f5ee..6550feac 100644 --- a/server/managers/RssFeedManager.js +++ b/server/managers/RssFeedManager.js @@ -52,11 +52,19 @@ class RssFeedManager { await this.db.updateEntity('feed', feed) } } else if (feed.entityType === 'collection') { - // TODO: Also trigger an update if any item in the collection was updated const collection = this.db.collections.find(c => c.id === feed.entityId) if (collection) { const collectionExpanded = collection.toJSONExpanded(this.db.libraryItems) - if (!feed.entityUpdatedAt || collection.lastUpdate > feed.entityUpdatedAt) { + + // Find most recently updated item in collection + let mostRecentlyUpdatedAt = collectionExpanded.lastUpdate + collectionExpanded.books.forEach((libraryItem) => { + if (libraryItem.media.tracks.length && libraryItem.updatedAt > mostRecentlyUpdatedAt) { + mostRecentlyUpdatedAt = libraryItem.updatedAt + } + }) + + if (!feed.entityUpdatedAt || mostRecentlyUpdatedAt > feed.entityUpdatedAt) { Logger.debug(`[RssFeedManager] Updating RSS feed for collection "${collection.name}"`) feed.updateFromCollection(collectionExpanded) diff --git a/server/objects/Feed.js b/server/objects/Feed.js index 4c42ece5..4f913460 100644 --- a/server/objects/Feed.js +++ b/server/objects/Feed.js @@ -167,7 +167,7 @@ class Feed { this.userId = userId this.entityType = 'collection' this.entityId = collectionExpanded.id - this.entityUpdatedAt = collectionExpanded.lastUpdate + this.entityUpdatedAt = collectionExpanded.lastUpdate // This will be set to the most recently updated library item this.coverPath = firstItemWithCover?.coverPath || null this.serverAddress = serverAddress this.feedUrl = feedUrl @@ -184,6 +184,8 @@ class Feed { this.episodes = [] itemsWithTracks.forEach((item, index) => { + if (item.updatedAt > this.entityUpdatedAt) this.entityUpdatedAt = item.updatedAt + item.media.tracks.forEach((audioTrack) => { const feedEpisode = new FeedEpisode() feedEpisode.setFromAudiobookTrack(item, serverAddress, slug, audioTrack, this.meta, index) @@ -211,6 +213,8 @@ class Feed { this.episodes = [] itemsWithTracks.forEach((item, index) => { + if (item.updatedAt > this.entityUpdatedAt) this.entityUpdatedAt = item.updatedAt + item.media.tracks.forEach((audioTrack) => { const feedEpisode = new FeedEpisode() feedEpisode.setFromAudiobookTrack(item, this.serverAddress, this.slug, audioTrack, this.meta, index) diff --git a/server/objects/mediaTypes/Book.js b/server/objects/mediaTypes/Book.js index 832b7c50..8443af08 100644 --- a/server/objects/mediaTypes/Book.js +++ b/server/objects/mediaTypes/Book.js @@ -136,11 +136,11 @@ class Book { } update(payload) { - var json = this.toJSON() + const json = this.toJSON() delete json.audiobooks // do not update media entities here delete json.ebooks - var hasUpdates = false + let hasUpdates = false for (const key in json) { if (payload[key] !== undefined) { if (key === 'metadata') {