From 217038b085c8be5cf5ef0781c4ff87f8d518e730 Mon Sep 17 00:00:00 2001 From: Greg Lorenzen Date: Mon, 14 Oct 2024 20:58:09 +0000 Subject: [PATCH 1/2] Fix and simplify filter logic for publishedDecades --- server/utils/queries/libraryItemsBookFilters.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/server/utils/queries/libraryItemsBookFilters.js b/server/utils/queries/libraryItemsBookFilters.js index e64e7b78..4b56bc47 100644 --- a/server/utils/queries/libraryItemsBookFilters.js +++ b/server/utils/queries/libraryItemsBookFilters.js @@ -229,9 +229,10 @@ module.exports = { mediaWhere['$series.id$'] = null } } else if (group === 'publishedDecades') { - const year = parseInt(value, 10) + const startYear = value.padStart(4, '0') + const endYear = (parseInt(value, 10) + 9).toString().padStart(4, '0') mediaWhere['publishedYear'] = { - [Sequelize.Op.between]: year >= 1000 ? [year, year + 9] : [year * 10, (year + 1) * 10 - 1] + [Sequelize.Op.between]: [startYear, endYear] } } From d2c405c1268910829babb8d486a8d7473b6ab29d Mon Sep 17 00:00:00 2001 From: advplyr Date: Tue, 15 Oct 2024 16:12:56 -0500 Subject: [PATCH 2/2] Fix decade filter and query by casting publishedYear to Int --- client/store/libraries.js | 4 ++-- server/utils/queries/libraryFilters.js | 6 +++--- server/utils/queries/libraryItemsBookFilters.js | 9 ++++----- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/client/store/libraries.js b/client/store/libraries.js index 81d32577..8964d9f1 100644 --- a/client/store/libraries.js +++ b/client/store/libraries.js @@ -309,9 +309,9 @@ export const mutations = { } // Add publishedDecades - if (mediaMetadata.publishedYear) { + if (mediaMetadata.publishedYear && !isNaN(mediaMetadata.publishedYear)) { const publishedYear = parseInt(mediaMetadata.publishedYear, 10) - const decade = Math.floor(publishedYear / 10) * 10 + const decade = (Math.floor(publishedYear / 10) * 10).toString() if (!state.filterData.publishedDecades.includes(decade)) { state.filterData.publishedDecades.push(decade) state.filterData.publishedDecades.sort((a, b) => a - b) diff --git a/server/utils/queries/libraryFilters.js b/server/utils/queries/libraryFilters.js index fc04fefc..34c3fe54 100644 --- a/server/utils/queries/libraryFilters.js +++ b/server/utils/queries/libraryFilters.js @@ -508,9 +508,9 @@ module.exports = { } if (book.publisher) data.publishers.add(book.publisher) // Check if published year exists and is valid - if (book.publishedYear && !isNaN(book.publishedYear) && book.publishedYear > 0 && book.publishedYear < 3000 && book.publishedYear.toString().length === 4) { - const decade = Math.floor(book.publishedYear / 10) * 10 - data.publishedDecades.add(decade.toString()) + if (book.publishedYear && !isNaN(book.publishedYear) && book.publishedYear > 0 && book.publishedYear < 3000) { + const decade = (Math.floor(book.publishedYear / 10) * 10).toString() + data.publishedDecades.add(decade) } if (book.language) data.languages.add(book.language) } diff --git a/server/utils/queries/libraryItemsBookFilters.js b/server/utils/queries/libraryItemsBookFilters.js index 4b56bc47..e8b424ed 100644 --- a/server/utils/queries/libraryItemsBookFilters.js +++ b/server/utils/queries/libraryItemsBookFilters.js @@ -229,11 +229,11 @@ module.exports = { mediaWhere['$series.id$'] = null } } else if (group === 'publishedDecades') { - const startYear = value.padStart(4, '0') - const endYear = (parseInt(value, 10) + 9).toString().padStart(4, '0') - mediaWhere['publishedYear'] = { + const startYear = parseInt(value) + const endYear = parseInt(value, 10) + 9 + mediaWhere = Sequelize.where(Sequelize.literal('CAST(`book`.`publishedYear` AS INTEGER)'), { [Sequelize.Op.between]: [startYear, endYear] - } + }) } return { mediaWhere, replacements } @@ -505,7 +505,6 @@ module.exports = { } let { mediaWhere, replacements } = this.getMediaGroupQuery(filterGroup, filterValue) - let bookWhere = Array.isArray(mediaWhere) ? mediaWhere : [mediaWhere] // User permissions