RSS feed for collection to update when any item in the collection is updated #606

This commit is contained in:
advplyr 2022-12-28 18:08:03 -06:00
parent 9e4bc582cb
commit 315c83e4c3
4 changed files with 24 additions and 10 deletions

View file

@ -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)