From a43b93d7962fa3351db2fee4f7fa1f762259f977 Mon Sep 17 00:00:00 2001 From: advplyr Date: Sun, 18 Feb 2024 14:58:46 -0600 Subject: [PATCH] Fix:Clear library filter data cache when library item is updated #2597 --- server/Database.js | 13 ++++++++++++- server/models/LibraryItem.js | 6 ++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/server/Database.js b/server/Database.js index dd9a0550..3d4219e5 100644 --- a/server/Database.js +++ b/server/Database.js @@ -419,10 +419,21 @@ class Database { await this.models.libraryItem.fullCreateFromOld(oldLibraryItem) } + /** + * Save metadata file and update library item + * + * @param {import('./objects/LibraryItem')} oldLibraryItem + * @returns {Promise} + */ async updateLibraryItem(oldLibraryItem) { if (!this.sequelize) return false await oldLibraryItem.saveMetadata() - return this.models.libraryItem.fullUpdateFromOld(oldLibraryItem) + const updated = await this.models.libraryItem.fullUpdateFromOld(oldLibraryItem) + // Clear library filter data cache + if (updated) { + delete this.libraryFilterData[oldLibraryItem.libraryId] + } + return updated } async removeLibraryItem(libraryItemId) { diff --git a/server/models/LibraryItem.js b/server/models/LibraryItem.js index ee8a4bb8..c7da31f6 100644 --- a/server/models/LibraryItem.js +++ b/server/models/LibraryItem.js @@ -225,6 +225,12 @@ class LibraryItem extends Model { return newLibraryItem } + /** + * Updates libraryItem, book, authors and series from old library item + * + * @param {oldLibraryItem} oldLibraryItem + * @returns {Promise} true if updates were made + */ static async fullUpdateFromOld(oldLibraryItem) { const libraryItemExpanded = await this.findByPk(oldLibraryItem.id, { include: [