jmcarp / nplusone

Auto-detecting the n+1 queries problem in Python
MIT License
1.01k stars 50 forks source link

Ignore queries retrieving no data #13

Closed twidi closed 8 years ago

twidi commented 8 years ago

If I use a relation (prefetched via prefetch_related in django for example) in a loop but the query returned no data, nplusone think that it's a "eager load'

It should only think this way if actual data is returned, because this causes a lot of false positive :(

jmcarp commented 8 years ago

Could you give an example of the kind of query that turns up this problem? Or, even better, write a failing test? I'll try to get this fixed quickly once I understand exactly what's going on.

twidi commented 8 years ago

Actually there is a lot more to do :)

I currently use your lib on a quite big django application and I discovered a lot of little and big problems.

I update my copy of ext/django/patch.py file on the go, and when done, I'll try to split in little pull requests (and leave some parts to be rewritten because I did some ugly hacks :) )

jmcarp commented 8 years ago

Thanks for your help!

twidi commented 8 years ago

I think in two days I spent more time managing "problems" with this lib than with the application I work for... but it's not a problem at all, It help us, and will help other after that.

PS: I think I'm starting to understand how the whole thing is currently working :D

jmcarp commented 8 years ago

@twidi: any updates on this? I'm looking forward to merging your pull requests and fixing bugs that you found. No problem if you don't have time to split up work into small pull requests.

jmcarp commented 8 years ago

I recently ran into this issue myself, and now I understand what you were saying--sorry I didn't figure this out earlier. Anyway, this should be improved as of 0.7.0. See #14 for updates. I'm going to close this for now, but please reopen or file a new issue if you continue to see problems.