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,15 +507,17 @@ module.exports = {
}) })
if (changedPodcasts === 0) { if (changedPodcasts === 0) {
// Verify that the count exists in the libraryFilterData object
if (Database.libraryFilterData[libraryId] && Database.libraryFilterData[libraryId].podcastCount) {
// If nothing has changed, check if the number of podcasts in // If nothing has changed, check if the number of podcasts in
// library is still the same as prior check before updating cache creation time // library is still the same as prior check before updating cache creation time
if (podcastCountFromDatabase === Database.libraryFilterData[libraryId].podcastCount) { if (podcastCountFromDatabase === Database.libraryFilterData[libraryId].podcastCount) {
Logger.debug(`Filter data for ${libraryId} has not changed, returning cached data and updating cache time after ${((Date.now() - start) / 1000).toFixed(2)}s`) 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() Database.libraryFilterData[libraryId].loadedAt = Date.now()
return cachedFilterData return cachedFilterData
} }
} }
}
// Something has changed in the podcasts table, so reload all of the filter data for library // Something has changed in the podcasts table, so reload all of the filter data for library
const podcasts = await Database.podcastModel.findAll({ const podcasts = await Database.podcastModel.findAll({
@ -611,6 +613,8 @@ module.exports = {
}) })
if (changedBooks + changedSeries + changedAuthors === 0) { if (changedBooks + changedSeries + changedAuthors === 0) {
// Verify that the counts exist in the libraryFilterData object
if (Database.libraryFilterData[libraryId] && Database.libraryFilterData[libraryId].bookCount && Database.libraryFilterData[libraryId].seriesCount && Database.libraryFilterData[libraryId].authorCount) {
// If nothing has changed, check if the number of authors, series, and books // If nothing has changed, check if the number of authors, series, and books
// matches the prior check before updating cache creation time // matches the prior check before updating cache creation time
if (bookCountFromDatabase === Database.libraryFilterData[libraryId].bookCount && seriesCountFromDatabase === Database.libraryFilterData[libraryId].seriesCount && authorCountFromDatabase === Database.libraryFilterData[libraryId].authorCount) { if (bookCountFromDatabase === Database.libraryFilterData[libraryId].bookCount && seriesCountFromDatabase === Database.libraryFilterData[libraryId].seriesCount && authorCountFromDatabase === Database.libraryFilterData[libraryId].authorCount) {
@ -619,6 +623,7 @@ module.exports = {
return cachedFilterData return cachedFilterData
} }
} }
}
// Store the counts for later comparison // Store the counts for later comparison
data.bookCount = bookCountFromDatabase data.bookCount = bookCountFromDatabase