mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-07-08 02:11:35 +00:00
perf: tighten derived filter cache policy
This commit is contained in:
parent
cdb0205f8d
commit
80eaccd1e6
7 changed files with 131 additions and 139 deletions
|
|
@ -21,6 +21,7 @@ class Database {
|
|||
|
||||
// Cached library filter data
|
||||
this.libraryFilterData = {}
|
||||
this.libraryFilterDataTtlMs = 1000 * 60 * 30
|
||||
|
||||
/** @type {import('./objects/settings/ServerSettings')} */
|
||||
this.serverSettings = null
|
||||
|
|
@ -583,6 +584,35 @@ class Database {
|
|||
this.libraryFilterData[libraryId].languages.push(language)
|
||||
}
|
||||
|
||||
getLibraryFilterCache(libraryId, { includeExpired = false } = {}) {
|
||||
const cacheEntry = this.libraryFilterData[libraryId]
|
||||
if (!cacheEntry) return undefined
|
||||
if (includeExpired) return cacheEntry
|
||||
|
||||
if (cacheEntry.expiresAt && cacheEntry.expiresAt > Date.now()) {
|
||||
return cacheEntry
|
||||
}
|
||||
|
||||
delete this.libraryFilterData[libraryId]
|
||||
return undefined
|
||||
}
|
||||
|
||||
setLibraryFilterCache(libraryId, data, ttlMs = this.libraryFilterDataTtlMs) {
|
||||
const loadedAt = Date.now()
|
||||
const expiresAt = loadedAt + ttlMs
|
||||
const cacheEntry = {
|
||||
...data,
|
||||
loadedAt,
|
||||
expiresAt
|
||||
}
|
||||
this.libraryFilterData[libraryId] = cacheEntry
|
||||
return cacheEntry
|
||||
}
|
||||
|
||||
invalidateLibraryFilterCache(libraryId) {
|
||||
delete this.libraryFilterData[libraryId]
|
||||
}
|
||||
|
||||
/**
|
||||
* Used when updating items to make sure author id exists
|
||||
* If library filter data is set then use that for check
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue