Stabilize download workflow scope during missing-model render

This commit is contained in:
Dariusz L
2026-07-22 12:48:05 +02:00
parent 07df118b18
commit c5215c2d3f
2 changed files with 16 additions and 9 deletions
@@ -394,6 +394,7 @@ export const resolveDownloadMethods = {
},
getDownloadWorkflowScopeIdentity(context = {}) {
if (typeof context === 'string') return context.trim();
const workflowKey = String(context.workflowKey || context.workflow_key || '').trim();
return String(
context.workflowTabId
@@ -417,10 +418,10 @@ export const resolveDownloadMethods = {
});
},
isDownloadInCurrentWorkflowScope(info = {}) {
isDownloadInCurrentWorkflowScope(info = {}, currentScope = null) {
const downloadScope = this.getDownloadWorkflowScopeIdentity(info);
const currentScope = this.getCurrentDownloadWorkflowScopeIdentity();
return !downloadScope || !currentScope || downloadScope === currentScope;
const scope = currentScope || this.getCurrentDownloadWorkflowScopeIdentity();
return !downloadScope || !scope || downloadScope === scope;
},
getDownloadMissingIdentity(missing) {
@@ -791,10 +792,12 @@ export const resolveDownloadMethods = {
return snapshot;
},
restoreDownloadedLocalMatchesForMissing(missing) {
restoreDownloadedLocalMatchesForMissing(missing, workflowScope = null) {
if (!missing) return missing;
const snapshot = this.getDownloadProgressStore().get(this.getDownloadStateKey(missing));
const snapshot = this.getDownloadProgressStore().get(
this.getDownloadStateKey(missing, workflowScope || null)
);
const storedMatches = Array.isArray(snapshot?.localMatches) ? snapshot.localMatches : [];
if (!storedMatches.length) return missing;
@@ -803,7 +806,7 @@ export const resolveDownloadMethods = {
return missing;
},
preserveActiveDownloadLocalMatches(missing, nextMatches = []) {
preserveActiveDownloadLocalMatches(missing, nextMatches = [], workflowScope = null) {
if (!missing) return Array.isArray(nextMatches) ? nextMatches : [];
const activeEntries = this.getActiveDownloadEntriesForMissing?.(missing) || [];
@@ -828,7 +831,7 @@ export const resolveDownloadMethods = {
const activeEntry = this.activeDownloads?.[activeDownload.download_id];
if (
activeEntry
&& (!this.isDownloadInCurrentWorkflowScope || this.isDownloadInCurrentWorkflowScope(activeEntry))
&& (!this.isDownloadInCurrentWorkflowScope || this.isDownloadInCurrentWorkflowScope(activeEntry, workflowScope))
&& activeEntry.missing !== missing
) {
activeEntry.missing = missing;
@@ -1811,12 +1811,16 @@ export const missingBrowserMethods = {
displayMissingModels(container, data, options = {}) {
const selectionOnly = !!options.selectionOnly;
const listScrollSnapshot = this.getMissingListScrollSnapshot(container);
// Resolving the download state used to serialize the whole workflow for
// every missing model. Keep the scope stable for this render pass.
const downloadWorkflowScope = this.getCurrentDownloadWorkflowScopeIdentity?.() || '';
const missingModels = (data.missing_models || []).map(missing => {
let restored = this.restoreDownloadedLocalMatchesForMissing?.(missing) || missing;
let restored = this.restoreDownloadedLocalMatchesForMissing?.(missing, downloadWorkflowScope) || missing;
restored = this.restoreSearchLocalHashMatchesForMissing?.(restored) || restored;
restored.matches = this.preserveActiveDownloadLocalMatches?.(
restored,
restored.matches || []
restored.matches || [],
downloadWorkflowScope
) || restored.matches || [];
return restored;
});