Skip to content

Commit f17d9c2

Browse files
committed
perf: allocate deck pull list in parallel instead of serially
Applying a pull list awaited one AllocateDeckCardItem mutation per physical copy in a sequential loop, so a 60-card pull meant 60 serial round trips. Run the entries through Promise.all instead. Each entry targets a distinct collection item (within a deck an item maps to a single deck card), so entries touch disjoint rows and can't race; copies of the same item within an entry stay serial to avoid racing on that item's availability. Wall-clock drops from the sum of all copies to the longest single entry. Addresses #104; collapsing the bulk update/delete Promise.all loops needs new server-side bulk mutations, tracked in #129.
1 parent 4e7ffb9 commit f17d9c2

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

‎assets/react/src/pages/decks/detail-page.tsx‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -651,8 +651,13 @@ export function DeckDetailPage({
651651
isPending: isAllocateDeckPullListPending,
652652
mutate: (entries: DeckPullListEntry[]) => {
653653
setIsAllocateDeckPullListPending(true)
654-
void (async () => {
655-
for (const entry of entries) {
654+
// Allocate entries in parallel instead of one serial round trip per copy.
655+
// Each entry targets a distinct collection item (within a deck an item maps
656+
// to a single deck card), so entries touch disjoint rows and can't race.
657+
// Copies of the same item within an entry stay serial to avoid racing on
658+
// that item's availability.
659+
void Promise.all(
660+
entries.map(async (entry) => {
656661
for (let copy = 0; copy < entry.quantity; copy += 1) {
657662
await client.mutate({
658663
mutation: AllocateDeckCardItemDocument,
@@ -662,8 +667,8 @@ export function DeckDetailPage({
662667
},
663668
})
664669
}
665-
}
666-
})()
670+
}),
671+
)
667672
.then(() => {
668673
const allocatedCount = entries.reduce((total, entry) => total + entry.quantity, 0)
669674

0 commit comments

Comments
 (0)