-
Notifications
You must be signed in to change notification settings - Fork 11.2k
refactor: split large org creation transaction into smaller batches #25688
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
The prisma.team.create call at L418 was creating the organization along with all orgProfiles and memberships in a single large transaction, which could timeout when there are many members. This change splits the operation into smaller, separate transactions: 1. Create the organization (team) with just metadata and organizationSettings 2. Create org profiles in batches of 50 using Promise.all 3. Create memberships in batches of 100 using createMany 4. Fetch created profiles to rebuild the member-profile mapping This approach avoids transaction timeouts while maintaining the same functionality and data integrity. Co-Authored-By: [email protected] <[email protected]>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 issues found across 1 file
Prompt for AI agents (all 2 issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="scripts/seed.ts">
<violation number="1" location="scripts/seed.ts:474">
P2: `profile.findMany` should explicitly `select` only `id`/`userId` instead of returning every column, per the repo’s Prisma query guidelines.</violation>
<violation number="2" location="scripts/seed.ts:485">
P2: Rebuilding `orgMembersInDBWithProfileId` is O(n²) because every member linearly searches `createdProfiles`. Build a lookup map (userId → profileId) once and read from it in O(1) per member.</violation>
</file>
Reply to cubic to teach it or ask questions. Re-run a review with @cubic-dev-ai review this PR
Explicit select is preferred, pointed out by cubic
Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
What does this PR do?
Splits the large
prisma.team.createtransaction inscripts/seed.ts(around L418) into smaller, separate operations to prevent transaction timeouts when seeding organizations with many members.The original code created the organization along with all orgProfiles and memberships in a single nested Prisma create, which could timeout on large datasets.
Changes:
Promise.allcreateManyMandatory Tasks (DO NOT REMOVE)
How should this be tested?
yarn db-seedHuman Review Checklist
accepted ?? falsefallback (line 468) is correct - original code passedaccepteddirectly without fallbackChecklist
Link to Devin run: https://app.devin.ai/sessions/ca372e66c88a44409019142f232172b2
Requested by: [email protected] (@emrysal)