From 185ccdf71cd7bd8c564bd5da467834903b15cafd Mon Sep 17 00:00:00 2001 From: FoxxMD Date: Mon, 17 Aug 2026 14:00:24 +0000 Subject: [PATCH] fix(source): Refactor existing play list used for existing check to use *all* processed plays Instead of just discovered, since we now dupe/discard plays that persist in db, change the cached existing list logic to include all processed plays --- src/backend/sources/AbstractSource.ts | 38 +++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/src/backend/sources/AbstractSource.ts b/src/backend/sources/AbstractSource.ts index 08e3d5f1..a7f688c0 100644 --- a/src/backend/sources/AbstractSource.ts +++ b/src/backend/sources/AbstractSource.ts @@ -442,12 +442,33 @@ export default abstract class AbstractSource extends AbstractComponent implement } protected recentDiscoveredCacheKey = () => { + return `recentDiscovered-${this.dbComponent.id}`; + } + + protected recentCacheKey = () => { return `recent-${this.dbComponent.id}`; } + getRecentlyDiscoveredPlays = async (hydrate: boolean = true): Promise => { const cacheKey = this.recentDiscoveredCacheKey(); let list = await this.cache.cacheDb.get(cacheKey); + if(list === undefined && hydrate) { + list = (await this.playRepo.findPlays({ + state: ['discovered'], + order: 'desc', + sort: 'playedAt', + limit: 200 + })).map(x => ({...asPlay(x.play), id: x.id, uid: x.uid})) + list.sort(sortByOldestPlayDate); + await this.cache.cacheDb.set(cacheKey, list, '2m'); + } + return list; + } + + getRecentPlays = async (hydrate: boolean = true): Promise => { + const cacheKey = this.recentCacheKey(); + let list = await this.cache.cacheDb.get(cacheKey); if(list === undefined && hydrate) { list = (await this.playRepo.findPlays({ stateNot: ['queued'], @@ -461,8 +482,8 @@ export default abstract class AbstractSource extends AbstractComponent implement return list; } - existingDiscovered = async (play: PlayObject): Promise => { - const list: PlayObject[] = await this.getRecentlyDiscoveredPlays(true); + async existingDiscovered(play: PlayObject): Promise { + const list: PlayObject[] = await this.getRecentPlays(true); const matchResults = await this.existingDiscoveredPlay(play, list); if(matchResults.match) { return matchResults.closestMatchedPlay; @@ -695,7 +716,6 @@ export default abstract class AbstractSource extends AbstractComponent implement await this.notify({title: `Polling Started`, message: 'Polling Started', priority: 'info'}); this.setStatus('Polling Started'); this.lastActivityAt = dayjs(); - let checkCount = 0; let checksOverThreshold = 0; const checkActiveFor = 120; let maxInterval = DEFAULT_POLLING_MAX_INTERVAL; @@ -960,13 +980,21 @@ export default abstract class AbstractSource extends AbstractComponent implement currQueuedPlay.parentId = existing.id; } this.playRepo.updateById(currQueuedPlay.id, {play: preCompared, state}); - const recentPlays = await this.getRecentlyDiscoveredPlays(false); + const recentPlays = await this.getRecentPlays(false); // only need to update if its already in memory, // and better to update in-memory than clear cache so we aren't refetching from db on every discover if(recentPlays !== undefined) { recentPlays.push({...preCompared, id: currQueuedPlay.id, uid: currQueuedPlay.uid}); recentPlays.sort(sortByOldestPlayDate); - this.cache.cacheDb.set(this.recentDiscoveredCacheKey(), recentPlays, '2m'); + this.cache.cacheDb.set(this.recentCacheKey(), recentPlays, '2m'); + } + if(state === 'discovered') { + const recentDiscoveredPlays = await this.getRecentlyDiscoveredPlays(false); + if(recentDiscoveredPlays !== undefined) { + recentDiscoveredPlays.push({...preCompared, id: currQueuedPlay.id, uid: currQueuedPlay.uid}); + recentDiscoveredPlays.sort(sortByOldestPlayDate); + this.cache.cacheDb.set(this.recentDiscoveredCacheKey(), recentDiscoveredPlays, '2m'); + } } updatedQueueState.queueStatus = 'completed'; -- 2.51.2