[Fixed]-API Endpoint Performance Improvement

1👍

From what I can tell, you don’t actually care about returning the model and you only use it to get a sum of a field, so you could just aggregate

daily_log_entries = LogEntry.objects.filter(daily_log=self, status__in=["driving", "onduty"])
daily_log_entries = daily_log_entries.aggregate(Sum('minutes_duration'))
total = daily_log_entries.minutes_duration__sum

I’m guessing that the majority of the time spent is by returning every value from your LogEntry object which is very wasteful, this just removes that need and just does exactly what you want, as well as performing that on the database side.

👤Sayse

Leave a comment