Add: check fields exist in filterData

This commit is contained in:
Nicholas Wallace 2024-11-17 20:42:02 -07:00
parent 2b0ba7d1e2
commit a326a90417

View File

@ -507,13 +507,15 @@ module.exports = {
}) })
if (changedPodcasts === 0) { if (changedPodcasts === 0) {
// If nothing has changed, check if the number of podcasts in // Verify that the count exists in the libraryFilterData object
// library is still the same as prior check before updating cache creation time if (Database.libraryFilterData[libraryId] && Database.libraryFilterData[libraryId].podcastCount) {
// If nothing has changed, check if the number of podcasts in
if (podcastCountFromDatabase === Database.libraryFilterData[libraryId].podcastCount) { // library is still the same as prior check before updating cache creation time
Logger.debug(`Filter data for ${libraryId} has not changed, returning cached data and updating cache time after ${((Date.now() - start) / 1000).toFixed(2)}s`) if (podcastCountFromDatabase === Database.libraryFilterData[libraryId].podcastCount) {
Database.libraryFilterData[libraryId].loadedAt = Date.now() Logger.debug(`Filter data for ${libraryId} has not changed, returning cached data and updating cache time after ${((Date.now() - start) / 1000).toFixed(2)}s`)
return cachedFilterData Database.libraryFilterData[libraryId].loadedAt = Date.now()
return cachedFilterData
}
} }
} }
@ -611,12 +613,15 @@ module.exports = {
}) })
if (changedBooks + changedSeries + changedAuthors === 0) { if (changedBooks + changedSeries + changedAuthors === 0) {
// If nothing has changed, check if the number of authors, series, and books // Verify that the counts exist in the libraryFilterData object
// matches the prior check before updating cache creation time if (Database.libraryFilterData[libraryId] && Database.libraryFilterData[libraryId].bookCount && Database.libraryFilterData[libraryId].seriesCount && Database.libraryFilterData[libraryId].authorCount) {
if (bookCountFromDatabase === Database.libraryFilterData[libraryId].bookCount && seriesCountFromDatabase === Database.libraryFilterData[libraryId].seriesCount && authorCountFromDatabase === Database.libraryFilterData[libraryId].authorCount) { // If nothing has changed, check if the number of authors, series, and books
Logger.debug(`Filter data for ${libraryId} has not changed, returning cached data and updating cache time after ${((Date.now() - start) / 1000).toFixed(2)}s`) // matches the prior check before updating cache creation time
Database.libraryFilterData[libraryId].loadedAt = Date.now() if (bookCountFromDatabase === Database.libraryFilterData[libraryId].bookCount && seriesCountFromDatabase === Database.libraryFilterData[libraryId].seriesCount && authorCountFromDatabase === Database.libraryFilterData[libraryId].authorCount) {
return cachedFilterData Logger.debug(`Filter data for ${libraryId} has not changed, returning cached data and updating cache time after ${((Date.now() - start) / 1000).toFixed(2)}s`)
Database.libraryFilterData[libraryId].loadedAt = Date.now()
return cachedFilterData
}
} }
} }