auto-save 2026-05-20 23:53 (~2)

This commit is contained in:
2026-05-20 23:55:28 +08:00
parent 76977543bd
commit e85be866e8
2 changed files with 37 additions and 16 deletions

View File

@@ -1853,6 +1853,13 @@
"message": "auto-save 2026-05-20 22:48 (~2)",
"hash": "a3d0c97",
"files_changed": 2
},
{
"ts": "2026-05-20T22:54:10+08:00",
"type": "commit",
"message": "auto-save 2026-05-20 22:54 (~3)",
"hash": "7697754",
"files_changed": 3
}
]
}

View File

@@ -389,24 +389,38 @@ export async function generateAssetPack(opts: {
};
}
while (remainingTemplates.length > 0) {
const readyTemplates = remainingTemplates
.filter(template => !template.anchorTemplateId || generatedTemplateIds.has(template.anchorTemplateId))
.slice(0, PACK_ASSET_CONCURRENCY);
if (!readyTemplates.length) {
throw new Error(`template anchor cycle or missing root: ${remainingTemplates.map(template => template.id).join(', ')}`);
const inFlight = new Set<Promise<void>>();
function takeReadyTemplate(): AssetTemplate | undefined {
const index = remainingTemplates.findIndex(template => !template.anchorTemplateId || generatedTemplateIds.has(template.anchorTemplateId));
if (index === -1) return undefined;
const [template] = remainingTemplates.splice(index, 1);
return template;
}
for (const template of readyTemplates) {
remainingTemplates.splice(remainingTemplates.indexOf(template), 1);
}
await Promise.all(readyTemplates.map(async template => {
function scheduleReadyTemplates() {
while (inFlight.size < PACK_ASSET_CONCURRENCY) {
const template = takeReadyTemplate();
if (!template) return;
const task = (async () => {
const asset = await createAsset(template);
assets.push(asset);
generatedTemplateIds.add(template.id);
await opts.onProgress?.(pack);
}));
})();
inFlight.add(task);
task.then(
() => inFlight.delete(task),
() => inFlight.delete(task),
);
}
}
while (remainingTemplates.length > 0 || inFlight.size > 0) {
scheduleReadyTemplates();
if (inFlight.size === 0) {
throw new Error(`template anchor cycle or missing root: ${remainingTemplates.map(template => template.id).join(', ')}`);
}
await Promise.race(inFlight);
}
const templateOrder = new Map(templates.map((template, index) => [template.id, index]));