Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix and simplify filter logic for publishedDecades #3518

Merged
merged 2 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions client/store/libraries.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions server/utils/queries/libraryFilters.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
10 changes: 5 additions & 5 deletions server/utils/queries/libraryItemsBookFilters.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,11 @@ module.exports = {
mediaWhere['$series.id$'] = null
}
} else if (group === 'publishedDecades') {
const year = parseInt(value, 10)
mediaWhere['publishedYear'] = {
[Sequelize.Op.between]: year >= 1000 ? [year, year + 9] : [year * 10, (year + 1) * 10 - 1]
}
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 }
Expand Down Expand Up @@ -504,7 +505,6 @@ module.exports = {
}

let { mediaWhere, replacements } = this.getMediaGroupQuery(filterGroup, filterValue)

let bookWhere = Array.isArray(mediaWhere) ? mediaWhere : [mediaWhere]

// User permissions
Expand Down
Loading