fix(character-dictionary): re-resolve AniList matches cached by the old season resolver

Version the anilist-resolution-cache.json file and drop entries written
before version 2, so seasons the old resolver landed one short on stop
being served from the cache.
This commit is contained in:
sudacode committed 2026-11-22 02:26:36 -08:00
1 parent b7b9400aae
commit 593c7cbc30
3 files changed
+39 -3

No files matched your search

+1 -1
View File
@@ -67,7 +67,7 @@ Read when: you need to find the owner module for a behavior or test surface
`delete-maintenance-scheduler.ts` coalesces and serializes stats deletes; the expensive work runs in `delete-maintenance-worker-thread.ts` while the tracker queues playback writes. Each batch uses one transaction, lexical update, rollup refresh, and incremental lifetime subtraction (`planLifetimeRemovals`/`applyLifetimeRemovals` in `lifetime.ts`). Merges, moves, AniList reassignments, and `stats cleanup -l` use `repairLifetimeSummariesFromMedia` (recompute from the per-video media ledger). The full lifetime rebuild survives only as the empty-table bootstrap; anywhere else it would collapse lifetime totals to the session retention window. `delete-maintenance-scheduler.ts` coalesces and serializes stats deletes; the expensive work runs in `delete-maintenance-worker-thread.ts` while the tracker queues playback writes. Each batch uses one transaction, lexical update, rollup refresh, and incremental lifetime subtraction (`planLifetimeRemovals`/`applyLifetimeRemovals` in `lifetime.ts`). Merges, moves, AniList reassignments, and `stats cleanup -l` use `repairLifetimeSummariesFromMedia` (recompute from the per-video media ledger). The full lifetime rebuild survives only as the empty-table bootstrap; anywhere else it would collapse lifetime totals to the session retention window.
- Immersion sync: `src/core/services/stats-sync/`, bound by `src/main/sync-cli.ts`. The sync window and auto-sync scheduler live in `src/main/assemblies/sync.ts`. - Immersion sync: `src/core/services/stats-sync/`, bound by `src/main/sync-cli.ts`. The sync window and auto-sync scheduler live in `src/main/assemblies/sync.ts`.
`snapshot-transfer.ts` selects compressed rsync or scp. `transfer-cache.ts` atomically retains the last successfully received snapshot per hashed peer/database identity under the config directory's `sync-transfer-cache/`. Cache copies seed isolated transfer directories; rsync verifies reconstructed files before the existing merge engine runs. The `--make-temp` / `--remove-temp` helpers accept an internal `--transfer-cache` key, with a fallback for older peers that do not recognize it. `snapshot-transfer.ts` selects compressed rsync or scp. `transfer-cache.ts` atomically retains the last successfully received snapshot per hashed peer/database identity under the config directory's `sync-transfer-cache/`. Cache copies seed isolated transfer directories; rsync verifies reconstructed files before the existing merge engine runs. The `--make-temp` / `--remove-temp` helpers accept an internal `--transfer-cache` key, with a fallback for older peers that do not recognize it.
- AniList tracking + character dictionary: `src/core/services/anilist/`, `src/main/runtime/composers/anilist-*` (called by `src/main/assemblies/anilist.ts`), `src/main/character-dictionary-runtime.ts`, `src/main/character-dictionary-runtime/`, assembled by `src/main/assemblies/character-dictionary.ts` - AniList tracking + character dictionary: `src/core/services/anilist/`, `src/main/runtime/composers/anilist-*` (called by `src/main/assemblies/anilist.ts`), `src/main/character-dictionary-runtime.ts`, `src/main/character-dictionary-runtime/`, assembled by `src/main/assemblies/character-dictionary.ts`. Every consumer maps a parsed title + season to an AniList entry through `anilist/season-resolver.ts` (sequel-chain walk; see its header for what counts as a season). Changing what it returns needs a `MEDIA_RESOLUTION_CACHE_VERSION` bump in `character-dictionary-runtime/cache.ts`, or old matches keep being served from `anilist-resolution-cache.json`.
- TMDB live-action metadata: `src/core/services/tmdb/` (client + exact-title resolver), `src/core/services/immersion-tracker/live-action-link.ts` (links an entry to a TMDB title and merges other holders of the same title). The AniList cover-art fetcher calls the resolver as its fallback; `imm_anime.media_kind` marks the result and keeps the entry out of AniList season repair. - TMDB live-action metadata: `src/core/services/tmdb/` (client + exact-title resolver), `src/core/services/immersion-tracker/live-action-link.ts` (links an entry to a TMDB title and merges other holders of the same title). The AniList cover-art fetcher calls the resolver as its fallback; `imm_anime.media_kind` marks the result and keeps the entry out of AniList season repair.
- Jellyfin integration: `src/core/services/jellyfin*.ts`, `src/main/runtime/composers/jellyfin-*`, - Jellyfin integration: `src/core/services/jellyfin*.ts`, `src/main/runtime/composers/jellyfin-*`,
assembled by `src/main/assemblies/jellyfin.ts` assembled by `src/main/assemblies/jellyfin.ts`
@@ -4,7 +4,13 @@ import * as os from 'os';
import * as path from 'path'; import * as path from 'path';
import test from 'node:test'; import test from 'node:test';
import { isDeepStrictEqual } from 'node:util'; import { isDeepStrictEqual } from 'node:util';
import { getSnapshotPath, readSnapshot, writeSnapshot } from './cache'; import {
getSnapshotPath,
readCachedMediaResolution,
readSnapshot,
writeCachedMediaResolution,
writeSnapshot,
} from './cache';
import { CHARACTER_DICTIONARY_FORMAT_VERSION } from './constants'; import { CHARACTER_DICTIONARY_FORMAT_VERSION } from './constants';
import type { CharacterDictionarySnapshot } from './types'; import type { CharacterDictionarySnapshot } from './types';
@@ -121,3 +127,20 @@ test('readSnapshot ignores snapshots written with an older format version', asyn
assert.equal(await readSnapshot(snapshotPath), null); assert.equal(await readSnapshot(snapshotPath), null);
}); });
test('media resolutions cached before the season resolver fix are re-resolved', () => {
const outputDir = makeTempDir();
const cachePath = path.join(outputDir, 'anilist-resolution-cache.json');
// Written by the old resolver, which counted "Season 2 Part 2" as season 3.
fs.writeFileSync(
cachePath,
JSON.stringify({
entries: [{ seriesKey: 'mushoku-tensei-s3', mediaId: 166873, mediaTitle: 'Part 2' }],
}),
);
assert.equal(readCachedMediaResolution(outputDir, 'mushoku-tensei-s3'), null);
const entry = { seriesKey: 'mushoku-tensei-s3', mediaId: 178789, mediaTitle: 'Season 3' };
writeCachedMediaResolution(outputDir, entry);
assert.deepEqual(readCachedMediaResolution(outputDir, 'mushoku-tensei-s3'), entry);
});
+14 -1
View File
@@ -28,9 +28,17 @@ type MediaResolutionCacheEntry = {
}; };
type MediaResolutionCacheFile = { type MediaResolutionCacheFile = {
version?: number;
entries?: MediaResolutionCacheEntry[]; entries?: MediaResolutionCacheEntry[];
}; };
/**
* Bump when the AniList season resolver changes what it returns, so matches it used to get
* wrong are re-resolved instead of being served from here forever. Version 2: split-cour
* continuations and specials no longer count as seasons.
*/
const MEDIA_RESOLUTION_CACHE_VERSION = 2;
function getMediaResolutionCachePath(outputDir: string): string { function getMediaResolutionCachePath(outputDir: string): string {
return path.join(outputDir, 'anilist-resolution-cache.json'); return path.join(outputDir, 'anilist-resolution-cache.json');
} }
@@ -55,6 +63,7 @@ function readMediaResolutionEntries(outputDir: string): MediaResolutionCacheEntr
const parsed = JSON.parse( const parsed = JSON.parse(
fs.readFileSync(getMediaResolutionCachePath(outputDir), 'utf8'), fs.readFileSync(getMediaResolutionCachePath(outputDir), 'utf8'),
) as MediaResolutionCacheFile; ) as MediaResolutionCacheFile;
if (parsed.version !== MEDIA_RESOLUTION_CACHE_VERSION) return [];
if (!Array.isArray(parsed.entries)) return []; if (!Array.isArray(parsed.entries)) return [];
const byKey = new Map<string, MediaResolutionCacheEntry>(); const byKey = new Map<string, MediaResolutionCacheEntry>();
for (const value of parsed.entries) { for (const value of parsed.entries) {
@@ -74,7 +83,11 @@ function writeMediaResolutionEntries(
ensureDir(outputDir); ensureDir(outputDir);
fs.writeFileSync( fs.writeFileSync(
getMediaResolutionCachePath(outputDir), getMediaResolutionCachePath(outputDir),
JSON.stringify({ entries }, null, 2), JSON.stringify(
{ version: MEDIA_RESOLUTION_CACHE_VERSION, entries } satisfies MediaResolutionCacheFile,
null,
2,
),
'utf8', 'utf8',
); );
} }