Skip to content

Commit d62abdc

Browse files
committed
OpenConceptLab/ocl_issues#2307 | Running 2 rows reranking concurrently
1 parent 02f417e commit d62abdc

1 file changed

Lines changed: 24 additions & 3 deletions

File tree

src/components/map-projects/MapProject.jsx

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,6 +1175,29 @@ const MapProject = () => {
11751175
}
11761176
};
11771177

1178+
const processRerankWithConcurrency = async (_rows, maxConcurrent = 2) => {
1179+
const queue = _rows.slice();
1180+
const activeRequests = new Set();
1181+
1182+
while (queue.length > 0 || activeRequests.size > 0) {
1183+
while (queue.length > 0 && activeRequests.size < maxConcurrent) {
1184+
if (abortRef.current) {
1185+
setLoadingMatches(false)
1186+
return
1187+
}
1188+
1189+
const row = queue.shift();
1190+
const promise = rerank(row.__index, true)
1191+
.catch(() => null)
1192+
.finally(() => activeRequests.delete(promise));
1193+
activeRequests.add(promise);
1194+
}
1195+
1196+
if(activeRequests.size > 0)
1197+
await Promise.race(activeRequests);
1198+
}
1199+
};
1200+
11781201
let subActions = [...map(algosSelected, algo => algo.name || algo.id)]
11791202
if(!isMultiAlgo)
11801203
subActions.push('reranker')
@@ -1200,9 +1223,7 @@ const MapProject = () => {
12001223
nextAlgo = getNextAlgoDef(nextAlgo.id)
12011224
}
12021225

1203-
for (const row of rows) {
1204-
await rerank(row.__index, true)
1205-
}
1226+
await processRerankWithConcurrency(rows, 2)
12061227
if(inAIAssistantGroup && autoRunAIAnalysis) {
12071228
await new Promise(resolve => setTimeout(resolve, 1000))
12081229
await runBulkAIAnalysis(rows)

0 commit comments

Comments
 (0)