| ▲ | bb88 9 hours ago | |
You may already know this, this is meant for others hitting this issue frankly. In Django, you can count the number of queries in a unit test. You don't need 1M objects in the unit test, but maybe 30 in your case. If the unit code uses more than X queries, then you should assume you have an N+1 bug. Like if you have 3 prefetch related and 2 select related's on 30 objects, but you end up with more than 30 queries, then you have an N+1 someplace. Even better that unit test will protect you from hitting that error in the future in that chunk of code accessing that table. | ||