Skip to content

Conversation

Copy link

Copilot AI commented Nov 14, 2025

Addresses performance feedback from #45 where nested loops with sequential await create N×M database round-trips during international price updates.

Changes:

  • Collect all upsert operations in an array during loop iteration
  • Execute batched operations with Promise.all after loop completion
  • Reduces database queries from N×M sequential to 2 initial + 1 parallel batch

Before:

for (const { currency, rate } of rates) {
  for (const offer of templateOffers) {
    await prisma.coinOffers.upsert({ ... }); // N×M sequential queries
  }
}

After:

const upsertOperations = [];
for (const { currency, rate } of rates) {
  for (const offer of templateOffers) {
    upsertOperations.push(prisma.coinOffers.upsert({ ... }));
  }
}
await Promise.all(upsertOperations); // Single parallel batch

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: dudantas <8551443+dudantas@users.noreply.github.com>
Copilot AI changed the title [WIP] WIP to address feedback on international price updates Batch database upserts to eliminate N×M sequential queries Nov 14, 2025
Copilot AI requested a review from dudantas November 14, 2025 17:35
@dudantas dudantas marked this pull request as ready for review November 17, 2025 15:27
@dudantas dudantas merged commit 19d32ab into dudantas/refactor-schedule-prices Nov 17, 2025
@dudantas dudantas deleted the copilot/sub-pr-45 branch November 17, 2025 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants