Company
Date Published
Author
Adam McKerlie
Word count
751
Language
English
Hacker News points
None

Summary

The author was building a simple website using Django to track expenses and expense reports. They noticed that their application was performing slowly due to N+1 problems caused by the Object-relational mapper (ORM). The ORM was generating multiple queries, including a single initial query and additional queries for each child object, leading to slow performance. By using `prefetch_related()` on the `expenses` field in the `Reports` model and annotating the `total_amount` field, the author was able to reduce the number of database queries and improve the application's performance, resulting in a 91% decrease in page load time.