mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-01-03 00:06:46 +01:00
Add: check for changes to library items
This commit is contained in:
parent
850ed48955
commit
435b7fda7e
@ -485,6 +485,60 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// To reduce the cold-start load time, first check if any library items, series,
|
||||||
|
// or authors have had an "updatedAt" timestamp since the last time the filter
|
||||||
|
// data was loaded. If so, we can skip loading all of the data.
|
||||||
|
// Because many items could change, just check the count of items.
|
||||||
|
const lastLoadedAt = cachedFilterData ? cachedFilterData.loadedAt : 0
|
||||||
|
|
||||||
|
const changedBooks = await Database.bookModel.count({
|
||||||
|
include: {
|
||||||
|
model: Database.libraryItemModel,
|
||||||
|
attributes: [],
|
||||||
|
where: {
|
||||||
|
libraryId: libraryId,
|
||||||
|
updatedAt: {
|
||||||
|
[Sequelize.Op.gt]: new Date(lastLoadedAt)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
where: {
|
||||||
|
updatedAt: {
|
||||||
|
[Sequelize.Op.gt]: new Date(lastLoadedAt)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
limit: 1
|
||||||
|
})
|
||||||
|
|
||||||
|
const changedSeries = await Database.seriesModel.count({
|
||||||
|
where: {
|
||||||
|
libraryId: libraryId,
|
||||||
|
updatedAt: {
|
||||||
|
[Sequelize.Op.gt]: new Date(lastLoadedAt)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
limit: 1
|
||||||
|
})
|
||||||
|
|
||||||
|
const changedAuthors = await Database.authorModel.count({
|
||||||
|
where: {
|
||||||
|
libraryId: libraryId,
|
||||||
|
updatedAt: {
|
||||||
|
[Sequelize.Op.gt]: new Date(lastLoadedAt)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
limit: 1
|
||||||
|
})
|
||||||
|
|
||||||
|
if (changedBooks + changedSeries + changedAuthors === 0) {
|
||||||
|
// If nothing has changed, update the cache to current time for 30 minute
|
||||||
|
// cache time and return the cached data
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
// Something has changed in one of the tables, so reload all of the filter data for library
|
||||||
const books = await Database.bookModel.findAll({
|
const books = await Database.bookModel.findAll({
|
||||||
include: {
|
include: {
|
||||||
model: Database.libraryItemModel,
|
model: Database.libraryItemModel,
|
||||||
|
Loading…
Reference in New Issue
Block a user