Our great sponsors
-
haxl
A Haskell library that simplifies access to remote data, such as databases or web-based services.
-
WorkOS
The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.
-
InfluxDB
Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.
See also django-zen-queries https://github.com/dabapps/django-zen-queries , which can make it impossible for changes to a template to trigger queries.
+1. The JS event loop auto-monad-izing Promises into Haxl [1]-esqe trees of implicitly-batched loads has been a big win for us building on JavaScript/TypeScript.
If I had to move to another language, I'd really want to find a "powered by the event loop / dataloader" framework, i.e. Vert.x for Java.
Also, per dataloader, a shameless plug for our ORM that has dataloader de-N+1-ing built natively into all object graph traversals:
On an unrelated note, Python folks should check out OP's library funcy [1]: "A collection of fancy functional tools focused on practicality. Inspired by clojure, underscore and my own abstractions."
Thanks for the library Suor!
Rails has Bullet[0] to help identify and warn you against N+1
Does Django have anything active? Quick search revealed nplusone[1] but its been dead since 2018.
Rails has Bullet[0] to help identify and warn you against N+1
Does Django have anything active? Quick search revealed nplusone[1] but its been dead since 2018.
Here is an example of such thing https://github.com/Suor/django-cacheops/blob/8b3a79de29b2545...
I was working on a library to do this which I never got around to fully finishing but the idea is there: https://github.com/lime-green/django-orm-plus I think all I had left was polishing the auto add logic and testing with a real project
Self plug: Checkout https://github.com/har777/pellet to easily find and fix django N+1 issues.
I usually add it to existing integration tests so that they raise exceptions on N+1. If test coverage is low then I would suggest sending the N+1 metrics to something like datadog. That way your users using the product will reveal all the N+1 issues on your monitoring solution.
Shameless plug - I ran into this while developing REST interfaces with Django and built django-auto-prefetching: https://github.com/GeeWee/django-auto-prefetching
It essentially travels your DRF serializer tree and builds an auto-prefetched query automatically without you needing to do any work.
Back when I still worked actively on it, I wanted to monkey-patch models to track whether or not n+1 was happening, and if it was, automatically do pre-fetching, so instead of an n+1 problem you'd end up with just a "3-4 queries when it could've been 1" problem - which is much more palatable. Never got around to that part though.
If I understand it correctly, that's what [django-seal](https://github.com/charettes/django-seal) does.