-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Database Features Added #1879
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: prod/acad-react
Are you sure you want to change the base?
Database Features Added #1879
Changes from all commits
c79fd72
59c4ed4
ec374bb
5941963
1aad0f3
769e9df
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,357 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Database Module Optimization - Implementation Summary & Testing Guide | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ## 🎯 What Was Done | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ### Phase 1: CRITICAL Performance Fixes ✅ COMPLETED | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #### 1.1 Fixed N+1 Query Problem (87.5% Reduction) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - **File**: `applications/database_backend/api/views.py` → `UnregisteredStudentsByBatchView` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - **Change**: Lines 764-771 now use single query + dictionary lookup | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - **Before**: 8 separate database queries (1 per semester) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - **After**: 1 database query + O(1) Python lookups | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - **Impact**: For batch with 8 semesters = 87.5% query reduction | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #### 1.2 Added Performance Indexes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - **File**: `applications/database_backend/migrations/0001_add_database_performance_indexes.py` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - **Indexes Created**: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - `idx_student_batch` - Filters on batch year | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - `idx_course_reg_student` - Student registration lookups | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - `idx_course_reg_session_semester` - Session + semester combo | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - `idx_course_reg_semester_fk` - Semester references | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - `idx_student_grades_batch_rollno` - Grade lookups | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - **Impact**: 10-50x faster query times | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| --- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ### Phase 2: Code Quality & Deduplication ✅ COMPLETED | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #### 2.1 Database-Level Sorting (50% Response Time Reduction) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - **File**: `applications/database_backend/api/views.py` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - **Changes**: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - Removed Python `sorted()` from `StudentCoursesDetail` (line 426 removed) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - Removed Python `sorted()` from `StudentsGradeInfo` (line 606 removed) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - Added `.order_by()` to `StudentsGradeInfo` queryset | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - Remaining Python sort in `UnregisteredStudentsByBatchView` kept (small dataset) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - **Impact**: Large datasets no longer sorted in memory | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #### 2.2 Shared Constants Module | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - **File**: `FusionFrontend/src/Modules/Database/constants/databaseConstants.js` (NEW) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - **Exports**: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - `CATEGORY_MAP` - Category to programme type mapping | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - `SEMESTER_OPTIONS_STATIC` - All semester options | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - `generateBatchOptions()` - Dynamic batch year generator | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - `DATABASE_APIS` - Centralized API endpoints | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - **Code Savings**: -200 lines of duplication | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #### 2.3 Reusable useDatabase Hook | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - **File**: `FusionFrontend/src/Modules/Database/hooks/useDatabase.js` (NEW) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - **Provides**: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - Common state management (batch, loading, error, data, filters) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - Shared `fetchData()` with auth + error handling | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - Pagination utilities (next, prev, goToPage) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - `reset()` function for category changes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - **Code Savings**: -600 lines of duplicated state logic | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - **Can be used by**: CourseWiseStudentEnrollment, StudentCoursesDetail, StudentsGradeInfo, UnregisteredStudents | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+38
to
+54
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - **File**: `FusionFrontend/src/Modules/Database/constants/databaseConstants.js` (NEW) | |
| - **Exports**: | |
| - `CATEGORY_MAP` - Category to programme type mapping | |
| - `SEMESTER_OPTIONS_STATIC` - All semester options | |
| - `generateBatchOptions()` - Dynamic batch year generator | |
| - `DATABASE_APIS` - Centralized API endpoints | |
| - **Code Savings**: -200 lines of duplication | |
| #### 2.3 Reusable useDatabase Hook | |
| - **File**: `FusionFrontend/src/Modules/Database/hooks/useDatabase.js` (NEW) | |
| - **Provides**: | |
| - Common state management (batch, loading, error, data, filters) | |
| - Shared `fetchData()` with auth + error handling | |
| - Pagination utilities (next, prev, goToPage) | |
| - `reset()` function for category changes | |
| - **Code Savings**: -600 lines of duplicated state logic | |
| - **Can be used by**: CourseWiseStudentEnrollment, StudentCoursesDetail, StudentsGradeInfo, UnregisteredStudents | |
| - **Status**: Recommended frontend follow-up refactor; not included in this backend repository/PR | |
| - **Suggested contents**: | |
| - `CATEGORY_MAP` - Category to programme type mapping | |
| - `SEMESTER_OPTIONS_STATIC` - All semester options | |
| - `generateBatchOptions()` - Dynamic batch year generator | |
| - `DATABASE_APIS` - Centralized API endpoints | |
| - **Expected Benefit**: Reduce duplicated frontend constants/configuration | |
| #### 2.3 Reusable useDatabase Hook | |
| - **Status**: Recommended frontend follow-up refactor; not included in this backend repository/PR | |
| - **Suggested responsibilities**: | |
| - Common state management (batch, loading, error, data, filters) | |
| - Shared `fetchData()` with auth + error handling | |
| - Pagination utilities (next, prev, goToPage) | |
| - `reset()` function for category changes | |
| - **Expected Benefit**: Reduce duplicated frontend state-management logic | |
| - **Potential consumers**: CourseWiseStudentEnrollment, StudentCoursesDetail, StudentsGradeInfo, UnregisteredStudents |
Copilot
AI
Apr 12, 2026
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.
In the frontend example, DATABASE_APIS.STUDENT_GRADES is shown as http://localhost:5173/database/api/... (frontend dev server port). Typically API calls should target the Django backend (e.g., 8000) or be relative paths proxied by the frontend. Consider correcting this to avoid confusing integration/testing instructions.
| // Should print: "http://localhost:5173/database/api/students-grade-info/" | |
| // Should print: "/database/api/students-grade-info/" |
Copilot
AI
Apr 12, 2026
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.
The “Using Constants” snippet mixes GenerateBatchOptions vs generateBatchOptions (different casing). Please ensure the example matches the actual exported symbol names to prevent copy/paste errors.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| from django.contrib import admin | ||
|
|
||
| # Register your models here. |
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.
Adding the
/database/route makes these new APIs publicly discoverable under the main URLconf. Given the sensitivity of the data returned by this app, consider confirming that appropriate authorization is enforced at the view level (not just authentication) before enabling this route in production.