Performance optimization: eliminate N+1 queries, add indexes, implement database-level pagination#64
Draft
Performance optimization: eliminate N+1 queries, add indexes, implement database-level pagination#64
Conversation
…nation Co-authored-by: kavyashri-as <213833080+kavyashri-as@users.noreply.github.com>
Co-authored-by: kavyashri-as <213833080+kavyashri-as@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Identified and fixed critical performance bottlenecks causing excessive database queries, full table scans, and in-memory processing of large datasets.
Changes
N+1 Query Elimination
GetCourseRegistrationsandGetStudentRegistrationsto eliminate redundant existence checksDatabase-Level Pagination
CourseService.GetCoursesAsyncandRegistrationService.GetRegistrationsAsyncnow paginate at database levelSearchCoursesPagedAsyncandGetRegistrationsWithFiltersPagedAsyncmethodsSELECT * → Count() in memory → Skip/Take in memorySELECT COUNT(*) → SELECT * OFFSET/FETCH at databaseDatabase Indexes
Added 7 performance indexes in
CourseRegistrationDbContext:Students.IsActive,Courses.IsActive,Courses.InstructorNameCourses.IsActive + StartDate(composite for available courses query)Registrations.Status,Registrations.StudentId,Registrations.CourseIdQuery Optimization
CourseRepository(5 methods).Include(c => c.Registrations)fromGetAvailableCoursesAsyncthat was loading 100k+ registration recordsMigration Required
cd api/CourseRegistration.Infrastructure dotnet ef migrations add AddPerformanceIndexes --startup-project ../CourseRegistration.API dotnet ef database update --startup-project ../CourseRegistration.APIDocumentation
PERFORMANCE_IMPROVEMENTS.md- detailed analysis with benchmarksPERFORMANCE_SUMMARY.md- quick reference guideImpact Estimates