Enhance error handling and optimize random algorithm for course allocation - #1940
Merged
vikrantwiz02 merged 1 commit intoJul 30, 2026
Merged
Conversation
…ize random_algo for course allocation
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.
This pull request significantly optimizes the course allocation logic in the academic information system by reducing the number of database queries and improving performance. The main changes involve batching queries and using bulk operations to replace inefficient per-object lookups and inserts, which should lead to faster allocations and less database load.
Performance and Query Optimization:
random_algo, replaced per-course and per-student queries with batched queries and precomputed dictionaries for course capacities, already allotted seats, student-curriculum mappings, and semester lookups. This reduces the number of queries from many per iteration to just a few per allocation run.random_algo, switched from creatingFinalRegistrationobjects one at a time to collecting them in a list and usingbulk_createat the end, greatly improving insert performance.allocate, replaced multiple queries per student with a single batched query per slot, and used dictionaries to map students to curricula and semesters. Final registrations are now inserted in bulk for each slot.Code Simplification and Consistency:
Error Handling Improvement:
start_allocation_apiby logging the exception with a traceback and returning a more informative error message including the exception type.