JMU-CIME / CPR-Music

1 stars 29 forks source link

Fix get_queryset(self) so the site doesn't take centuries to load #120

Open williamjedrzejczak opened 7 months ago

williamjedrzejczak commented 7 months ago

Would've made this a commit, however, since it's just one TODO figured it'd be better as a task

The Function def get_queryset(self) in views.py (in api) (in the backend) is contributing heavily to the long wait times.

How can we optimize this in a way which would reduce loading times?

Image

williamjedrzejczak commented 7 months ago

How on earth can we do this.

Current thoughts:

  1. Indexing: Ensure that the database fields used in filter(), get(), and the fields you join on (foreign keys) are indexed
  2. Defer fields: If there are large fields that aren't always needed (e.g., text fields with a lot of data), you can use .defer() to postpone loading. (or use only fields)
  3. Evaluate Query Patterns: Look at the query patterns to see if select_related and prefetch_related are being used properly. (Sometimes overuse can lead to unnecessary data being retrieved.)
  4. Database Profiling: Use Django Debug Toolbar maybe? or similar tools to learn where the bottlenecks are.
  5. Batch to process data with iterator() to save on memory.
  6. Optimize the database configuration settings.
  7. Review complex filtering logic in the queryset and see if we can make it more simple.