Skip to content

Commit 38f5130

Browse files
improvement(table): parallelize queued-stamp writes within concurrency-cap chunks
1 parent 9263521 commit 38f5130

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

apps/sim/lib/table/workflow-columns.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,14 @@ export async function scheduleRunsForRows(
202202
return { triggered: 0 }
203203
}
204204

205-
for (let i = 0; i < pendingRuns.length; i++) {
206-
await stampQueuedOrCancel(queue, pendingRuns[i], jobIds[i])
205+
// Stamp `queued` in chunks of `TABLE_CONCURRENCY_LIMIT`. Within a chunk we
206+
// parallelize the writes (no ordering constraint); across chunks we await
207+
// serially so trigger.dev still picks rows up in submission order — the
208+
// concurrency cap means at most one chunk is in flight per table anyway.
209+
for (let i = 0; i < pendingRuns.length; i += TABLE_CONCURRENCY_LIMIT) {
210+
const chunk = pendingRuns.slice(i, i + TABLE_CONCURRENCY_LIMIT)
211+
const ids = jobIds.slice(i, i + TABLE_CONCURRENCY_LIMIT)
212+
await Promise.all(chunk.map((run, j) => stampQueuedOrCancel(queue, run, ids[j])))
207213
}
208214
return { triggered: pendingRuns.length }
209215
} catch (err) {

0 commit comments

Comments
 (0)