按宿主已派发记录计算图位预算
This commit is contained in:
parent
2a6b05fd94
commit
a4483a0d64
@ -462,12 +462,8 @@ export async function openProductionOperations(host,{maxActiveDelegates=6,maxGen
|
||||
remainingGenerationAttempts:Math.max(0,maxGenerationAttempts-generationAttempts),
|
||||
drawLimitReached:generationAttempts>=maxGenerationAttempts,
|
||||
});
|
||||
const drawStatuses=selected=>{
|
||||
const ids=new Map(selected.map(slot=>[slot.id,nativeGenerations(slot)]));
|
||||
const counts=repository.countImageGenerations(binding,ids,journal.items);
|
||||
return new Map([...counts].map(([id,count])=>[id,drawStatus(count)]));
|
||||
};
|
||||
const slotDrawStatus=slot=>drawStatuses([slot]).get(slot.id);
|
||||
const slotDrawStatus=slot=>drawStatus(new Set(nativeGenerations(slot)).size);
|
||||
const drawStatuses=selected=>new Map(selected.map(slot=>[slot.id,slotDrawStatus(slot)]));
|
||||
const drawLimit=(slot,status)=>({slotId:slot.id,phase:'draw_limit_reached',limitReached:true,...status,
|
||||
candidates:slot.candidates??[],
|
||||
reason:`该图位已达到单张最多 ${maxGenerationAttempts} 次生图上限,请从已有候选中择优采纳(或使用实拍裁切/调整),后续可由人工通过引用精修。`,
|
||||
|
||||
@ -229,36 +229,6 @@ export class ProjectRepository {
|
||||
return this.#open(db => this.#readRequest(db, requestId));
|
||||
}
|
||||
|
||||
#countImageGenerations(requests, nativeIds, item) {
|
||||
const ids = new Set(nativeIds);
|
||||
for (const {request_id, state} of requests) {
|
||||
if (state !== 'prepared') ids.add(request_id);
|
||||
}
|
||||
for (const row of item?.attempts ?? []) if (row.source === 'generate' && row.candidateId) ids.add(row.candidateId);
|
||||
for (const id of Object.keys(item?.pendingGenerations ?? {})) ids.add(id);
|
||||
const originalId = item?.pendingOperation?.candidateId;
|
||||
if (originalId && !item.attempts?.some(row => row.candidateId === originalId && row.source === 'product')) {
|
||||
ids.add(originalId);
|
||||
}
|
||||
return ids.size;
|
||||
}
|
||||
|
||||
#generationRequests(db, binding, slotId) {
|
||||
return db.prepare(`SELECT slot_id, request_id, state FROM image_requests
|
||||
WHERE ${scopeWhere} AND json_extract(prepared_json, '$.binding') = ?${slotId ? ' AND slot_id = ?' : ''}`)
|
||||
.all(...this.scope, binding, ...(slotId ? [slotId] : []));
|
||||
}
|
||||
|
||||
countImageGenerations(binding, nativeIdsBySlot, items) {
|
||||
if (!nativeIdsBySlot.size) return new Map();
|
||||
return this.#open(db => {
|
||||
const slotId = nativeIdsBySlot.size === 1 ? nativeIdsBySlot.keys().next().value : undefined;
|
||||
const requests = Map.groupBy(this.#generationRequests(db, binding, slotId), row => row.slot_id);
|
||||
return new Map([...nativeIdsBySlot].map(([id, nativeIds]) =>
|
||||
[id, this.#countImageGenerations(requests.get(id) ?? [], nativeIds, items[id])]));
|
||||
});
|
||||
}
|
||||
|
||||
#recordCandidate(db, slotId, candidateId, kind, detail) {
|
||||
db.prepare(`INSERT INTO candidate_evidence (${scopeColumns}, slot_id, candidate_id, kind, detail_json)
|
||||
VALUES (${scopeValues}, ?, ?, ?, ?)`).run(...this.scope, slotId, candidateId, kind, json(detail));
|
||||
|
||||
@ -160,7 +160,9 @@ test('a host-owned original survives a Pi restart and is recovered without anoth
|
||||
});
|
||||
|
||||
test('a candidate reserved before POST neither owns the slot nor spends its draw budget',async t=>{
|
||||
const {host}=await tailFixture(t,['hero']);
|
||||
const {host}=await tailFixture(t,['hero'],{
|
||||
hero:{state:'unknown',pendingGenerations:{'reserved-before-send':{candidateId:'reserved-before-send'}}},
|
||||
});
|
||||
const workflowRead=host.canvas.workflowRead;
|
||||
host.canvas.workflowRead=async input=>{
|
||||
const view=await workflowRead(input);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user