Compare commits

...
Author SHA1 Message Date
FoxxMD a4acf020d6 Add more tracing around recently discovered usage 2026-04-02 01:31:48 +00:00
FoxxMD fe60126927 Add temp trace call site tracing for lz #497 2026-04-02 01:31:48 +00:00
3 changed files with 25 additions and 8 deletions
+4
View File
@@ -33,6 +33,10 @@ class TupleMap<X,Y,Z> {
return this.map.values();
}
keys() {
return this.map.keys().map(x => JSON.parse(x));
}
forEach(callbackfn: (value: Z, key: [X, Y], map: Map<string, Z>) => void, thisArg?: any): void {
this.map.forEach((value, key) => {
callbackfn.call(thisArg, value, JSON.parse(key), this.map);
+18 -6
View File
@@ -31,7 +31,7 @@ import {
sleep,
sortByOldestPlayDate,
} from "../utils.js";
import { sortByNewestPlayDate } from '../../core/PlayUtils.js';
import { genGroupIdStr, sortByNewestPlayDate } from '../../core/PlayUtils.js';
import { formatNumber } from '../../core/DataUtils.js';
import { timeToHumanTimestamp } from "../../core/TimeUtils.js";
import { todayAwareFormat } from "../../core/TimeUtils.js";
@@ -198,9 +198,14 @@ export default abstract class AbstractSource extends AbstractComponent implement
protected addPlayToDiscovered = (play: PlayObject) => {
const platformId = this.multiPlatform ? genGroupId(play) : SINGLE_USER_PLATFORM_ID;
const list = this.recentDiscoveredPlays.get(platformId) ?? new FixedSizeList<ProgressAwarePlayObject>(200);
let list: FixedSizeList<ProgressAwarePlayObject> = this.recentDiscoveredPlays.get(platformId);
if(list === undefined) {
this.logger.trace(`Creating new discovered list for platform ${genGroupIdStr(platformId)}`);
list = new FixedSizeList<ProgressAwarePlayObject>(200);
this.recentDiscoveredPlays.set(platformId, list);
}
this.logger.trace(`Adding new discovered play to discovered list ${genGroupIdStr(platformId)} with ${list.length} existing`);
list.add(play);
this.recentDiscoveredPlays.set(platformId, list);
this.tracksDiscovered++;
this.logger.info(`Discovered => ${buildTrackString(play)}`);
this.emitEvent('discovered', {play});
@@ -218,16 +223,21 @@ export default abstract class AbstractSource extends AbstractComponent implement
data.sort(sortByOldestPlayDate);
return data;
}
this.logger.trace(`Tried to get non-existent recently discovered for platform ${genGroupIdStr(platformId)}`);
return [];
}
protected getExistingDiscoveredLists = (play: PlayObject, opts: {checkAll?: boolean} = {}): PlayObject[][] => {
const lists: PlayObject[][] = [];
if(opts.checkAll !== true) {
lists.push(this.getRecentlyDiscoveredPlaysByPlatform(this.multiPlatform ? genGroupId(play) : SINGLE_USER_PLATFORM_ID));
if(opts.checkAll !== true || !this.multiPlatform) {
const plat = this.multiPlatform ? genGroupId(play) : SINGLE_USER_PLATFORM_ID;
lists.push(this.getRecentlyDiscoveredPlaysByPlatform(plat));
if(lists.every(x => x.length === 0)) {
this.logger.trace(`Got empty discovered list for platform ${genGroupIdStr(plat)}`);
}
} else {
// get as many as we can, optionally filtering by user
this.recentDiscoveredPlays.forEach((list, platformId) => {
this.recentDiscoveredPlays.keys().forEach((platformId) => {
if(play.meta.user !== undefined) {
if(platformId[1] === NO_USER || platformId[1] === play.meta.user) {
lists.push(this.getRecentlyDiscoveredPlaysByPlatform(platformId));
@@ -262,6 +272,8 @@ export default abstract class AbstractSource extends AbstractComponent implement
}
discover = async (plays: PlayObject[], options: { checkAll?: boolean, [key: string]: any } = {}): Promise<PlayObject[]> => {
this.logger.trace(`Discover on ${plays.length} plays`);
const newDiscoveredPlays: PlayObject[] = [];
for await(const play of pMapIterable(plays, this.staggerMappers.preCompare(async x => await this.transformPlay(x, TRANSFORM_HOOK.preCompare)), {concurrency: 2})) {
+3 -2
View File
@@ -9,7 +9,8 @@ import {
CALCULATED_PLAYER_STATUSES,
InternalConfig, PlayerStateDataMaybePlay,
PlayPlatformId,
ProgressAwarePlayObject} from "../common/infrastructure/Atomic.js";
ProgressAwarePlayObject,
SINGLE_USER_PLATFORM_ID} from "../common/infrastructure/Atomic.js";
import { SourceType, SourceConfig } from '../common/infrastructure/config/source/sources.js';
import { PollingOptions } from "../common/infrastructure/config/common.js";
import {
@@ -341,7 +342,7 @@ export default class MemorySource extends AbstractSource {
}
return [false, `${stPrefix} ${EXPECTED_NON_DISCOVERED_REASON}`]
} else {
const discoveredPlays = this.getRecentlyDiscoveredPlaysByPlatform(genGroupId(candidate));
const discoveredPlays = this.getRecentlyDiscoveredPlaysByPlatform(this.multiPlatform ? genGroupId(candidate) : SINGLE_USER_PLATFORM_ID);
if (discoveredPlays.length === 0 || !playObjDataMatch(discoveredPlays[0], candidate)) {
// if most recent stateful play is not this track we'll add it
return [true,`${stPrefix} added after ${thresholdResultSummary(thresholdResults)}. Matched other recent play but could not determine time frame due to missing duration. Allowed due to not being last played track.`];