Skip to content

Commit 06b2507

Browse files
committed
feat: 修复genlab轮询问题
1 parent 661a2e4 commit 06b2507

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

ui/src/components/debug/utils/imageGenerationUtils.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ export const handleStartGeneration = async (
139139
const primaryNodeId = Object.keys(paramTestValues)[0];
140140
const primaryNodeName = selectedNodeInfoMap[primaryNodeId] || "Unknown Node";
141141

142+
const finished_ids = {}
142143
// Start polling for images
143144
pollForImages(
144145
prompt_ids,
@@ -150,6 +151,7 @@ export const handleStartGeneration = async (
150151
pollingSessionIdRef,
151152
pollingTimeoutRef,
152153
updateState,
154+
finished_ids,
153155
primaryNodeName,
154156
paramTestValues,
155157
totalCombinations,
@@ -175,6 +177,7 @@ export const pollForImages = async (
175177
pollingSessionIdRef: React.MutableRefObject<string | null>,
176178
pollingTimeoutRef: React.MutableRefObject<NodeJS.Timeout | null>,
177179
updateState: (key: StateKey, value: any) => void,
180+
finished_ids: Record<string, boolean>,
178181
nodeName?: string,
179182
paramTestValues?: {[nodeId: string]: {[paramName: string]: any[]}},
180183
totalCount?: number,
@@ -186,10 +189,8 @@ export const pollForImages = async (
186189
console.log("Another polling session has started, stopping this one");
187190
return;
188191
}
189-
// has avaiable promptId,if not, stop polling
190-
const hasAvailablePromptId = prompt_ids.some(id => !!id && id !== '')
191192
// Check if timeout has been reached or has no avaiable promptId
192-
if (Date.now() - startTime > timeoutDuration || !hasAvailablePromptId) {
193+
if (Date.now() - startTime > timeoutDuration) {
193194
console.log("Timeout reached while waiting for images");
194195
if (pollingSessionIdRef.current === sessionId) {
195196
updateState(StateKey.IsProcessing, false);
@@ -225,7 +226,7 @@ export const pollForImages = async (
225226
// Check each prompt id to see if images are ready
226227
for (let i = 0; i < prompt_ids.length; i++) {
227228
const promptId = prompt_ids[i];
228-
if (!promptId) continue;
229+
if (!promptId || finished_ids[promptId]) continue;
229230

230231
try {
231232
// We've already verified showNodeId is not null at this point
@@ -235,10 +236,11 @@ export const pollForImages = async (
235236
// If we have an image URL, update in our array
236237
newImages[i] = {
237238
...newImages[i],
238-
url: imageUrl || ''
239+
url: imageUrl
239240
};
241+
finished_ids[promptId] = true
242+
completedImagesCount++;
240243
}
241-
completedImagesCount++;
242244
} catch (error) {
243245
console.error(`Error fetching image for prompt ID ${promptId}:`, error);
244246
}
@@ -293,6 +295,7 @@ export const pollForImages = async (
293295
pollingSessionIdRef,
294296
pollingTimeoutRef,
295297
updateState,
298+
finished_ids,
296299
nodeName,
297300
paramTestValues,
298301
totalCount,

0 commit comments

Comments
 (0)