Add database indexes to improve query performance#113
Open
Conversation
- Add db_index=True to Question.filename and Question.Hash - Add db_index=True to Course.name and Course.university - Add db_index=True to UploadedFile.filename These indexes will significantly improve query performance for search operations and file lookups, especially as the database grows. The indexed fields are frequently used in filter() and get() operations throughout the codebase. Co-Authored-By: 治乾徐 <18948336448@163.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.
Add database indexes to improve query performance
Summary
This PR adds database indexes to 5 frequently queried model fields to improve search and lookup performance:
filenameandHashfieldsnameanduniversityfieldsfilenamefieldThese fields are used extensively in filter() and get() operations throughout the codebase, particularly in search functionality (search.py), PDF reader lookups (views.py), and upload operations (upload.py). As the database grows, these indexes will significantly reduce query times by avoiding full table scans.
Review & Testing Checklist for Human
python manage.py makemigrationsto create the migration that adds these indexes. Review the generated migration to ensure it looks correct.python manage.py migrateand verify no errors occur.db_index=Trueto TextField fields works as expected with PostgreSQL. Consider whether any of these fields would benefit from full-text search indexes instead.Notes
Link to Devin run: https://app.devin.ai/sessions/5d7be24cadee44318538178baa782d1b
Requested by: 治乾徐 (xuzhiqian.430@bytedance.com) / @LoriXu430