Prevent Django Admin default queries on primary media tables in production #4344
Labels
💻 aspect: code
Concerns the software code in the repository
🧰 goal: internal improvement
Improvement that benefits maintainers, not users
🟧 priority: high
Stalls work on the project or its dependents
🧱 stack: api
Related to the Django API
Description
On several occasions now, we've run into production resource issues with our database due to Django Admin performing some default query against our (massive) primary media tables (e.g. #970).
Recent changes to the reporting admin (specifically #4254) have added new views that are also selecting the primary media tables in order to generate the UI. These are incredibly useful for local testing, but are actively harmful for production.
We should alter the logic for these fields so that the automatic completion only occurs locally and does not occur in production. This will help prevent issues from occurring from simply visiting pages in Django Admin in production.Going forward (per @sarayourfriend's comment #4344 (comment)), we should create a custom object manager for the media models that ensures the following things:
ORDER BY
is not used on the base media tablesLIMIT
is always defined for queries on the media tablesThis would prevent us from erroneously adding naive queries that could impact production in the future, even if we add the functionality for the query in a naive way.
The text was updated successfully, but these errors were encountered: