fix(identity): 自动识别新建作品后排一次元数据刷新

bindAuto 经 createEntityFromTmdb 新建作品时,事务提交后入队 full refreshMetadata
(幂等键 refreshMetadata:created:<作品>,与人工指定 / 整理接管同一做法)。新建档没有季表时
资源按原号放行(unverified),刷新补齐季表后重算为换算结果。

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Cxwgnn2pbzQ7rXv3rq7fei
This commit is contained in:
rootandClaude Opus 5.5 committed 2026-10-03 20:38:50 +08:00
1 parent c16f8a51e9
commit b02b4a500f
2 files changed
+117 -14

No files matched your search

@@ -35,6 +35,7 @@ import {
looksLikeVariety,
resolveEntityId,
} from "./entities.ts";
import { enqueueNewEntityRefresh } from "./entity-from-candidate.ts";
import {
canonicalParsed,
clearReleaseEpisodes,
@@ -714,8 +715,10 @@ async function bindAuto(
const site = ((release.raw as Record<string, unknown>)?._site ?? {}) as { categoryName?: string };
const variety = looksLikeVariety(parsed, site.categoryName ?? release.category_raw);
for (let attempt = 0; ; attempt++) {
// 本次新建的作品:事务提交后排一次 full 元数据刷新(季表、集单元),刷新完成会重算待确认 / 放行资源的集数
let created: string | null = null;
try {
return await ctx.db.transaction().execute(async (trx) => {
const result = await ctx.db.transaction().execute(async (trx) => {
let entityId: string | null = null;
if (best.candidate.localEntityId) entityId = await resolveEntityId(trx, best.candidate.localEntityId);
if (!entityId && best.candidate.provider === "tmdb") {
@@ -725,19 +728,19 @@ async function bindAuto(
externalId: best.candidate.externalId,
});
if (!entityId && tmdbDetail) {
entityId = (
await createEntityFromTmdb(trx, tmdbDetail, {
level,
evidence: {
sourceReleaseId: release.id,
rules: best.evidence,
titleMatch: best.titleMatch,
yearMatch: best.yearMatch,
},
actor: SYSTEM,
variety,
})
).entityId;
const r = await createEntityFromTmdb(trx, tmdbDetail, {
level,
evidence: {
sourceReleaseId: release.id,
rules: best.evidence,
titleMatch: best.titleMatch,
yearMatch: best.yearMatch,
},
actor: SYSTEM,
variety,
});
entityId = r.entityId;
if (r.created) created = r.entityId;
}
}
if (!entityId)
@@ -848,6 +851,8 @@ async function bindAuto(
reason: resolution.reason,
};
});
if (created) await enqueueNewEntityRefresh(ctx, created);
return result;
} catch (e) {
if (e instanceof IdentityConflictError && attempt < 2) continue;
throw e;