Skip to content

Fix: optimize prisma seeder to reduce DB queries and improve performance#999

Merged
dr5hn merged 1 commit into
dr5hn:masterfrom
Khuzaima01:fix-prisma-seeder
Mar 31, 2025
Merged

Fix: optimize prisma seeder to reduce DB queries and improve performance#999
dr5hn merged 1 commit into
dr5hn:masterfrom
Khuzaima01:fix-prisma-seeder

Conversation

@Khuzaima01
Copy link
Copy Markdown
Contributor

Refactored the Prisma seeding process to enhance performance and efficiency by:

βœ… Batch Inserts: Used createMany with skipDuplicates: true to insert multiple records at once, reducing database queries.
βœ… Efficient Lookups: Pre-fetched and mapped region, subregion, country, and state IDs into memory to minimize repeated findUnique queries.
βœ… Improved Data Integrity: Ensured valid relationships by checking for existing stateId and countryId before inserting dependent records.
βœ… Progress Logging: Added console logs to monitor the seeding process and track execution time.
βœ… Better Error Handling: Implemented structured error logging to identify and debug issues efficiently.

These improvements significantly reduce execution time and improve the overall efficiency of the Prisma seeders.

Refactored the Prisma seeding process to enhance performance and efficiency by:

βœ… Batch Inserts: Used createMany with skipDuplicates: true to insert multiple records at once, reducing database queries.
βœ… Efficient Lookups: Pre-fetched and mapped region, subregion, country, and state IDs into memory to minimize repeated findUnique queries.
βœ… Improved Data Integrity: Ensured valid relationships by checking for existing stateId and countryId before inserting dependent records.
βœ… Progress Logging: Added console logs to monitor the seeding process and track execution time.
βœ… Better Error Handling: Implemented structured error logging to identify and debug issues efficiently.

These improvements significantly reduce execution time and improve the overall efficiency of the Prisma seeders.
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. enhancement New feature or request labels Mar 30, 2025
@Khuzaima01 Khuzaima01 changed the title Fix: Optimize prisma seeder to reduce DB queries and improve performance Fix: optimize prisma seeder to reduce DB queries and improve performance Mar 30, 2025
@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Mar 31, 2025
@dr5hn dr5hn merged commit 683542f into dr5hn:master Mar 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants