News for hackers. Stuff that matters.
Re:Ban 1+N in Django by wruza on Sunday March 26, 2023 @10:19PM (#35322161)
I wonder why ORMs still(?) work as simple wrappers and never track access patterns. If you see that `in books` generator’s results experience accesses through a relationship, it’s pretty obvious to join it in advance after few misses and serve `book.author.full_name` from cache.

Of course that would make ORM more complex, but why would you need one otherwise. A good database interface should make good guesses, probably with some hints that could be slapped over without changing naive code patterns. But instead we get 1000 different cool ways to create a table and select a row by id.

Re:Ban 1+N in Django by nicoburns on Sunday March 26, 2023 @11:04PM (#35322402)
Because people want their queries to have predictable performance.
Re:Ban 1+N in Django by marcosdumay on Sunday March 26, 2023 @11:43PM (#35322629)
Interestingly, they never get it. Every layer of the stack up to the client's database connector is unpredictable.

But yes, people want it. And will trade a lot of performance for a false promise of predictability.

Re:Ban 1+N in Django by danielheath on Sunday March 26, 2023 @11:43PM (#35322622)
I don't want my app to change performance-sensitive behavior at runtime, that's a debugging nightmare.

I do want my framework to throw an error in development mode if I screw up the preloading.

Re:Ban 1+N in Django by wruza on Monday March 27, 2023 @06:51AM (#35325062)
Since this also requires the same heuristics, it could be just an option: orm.unroll(“auto|throw|none”). Would suit you, me and a commenter who wants hundreds of requests as they wrote.
Re:Ban 1+N in Django by fud101 on Monday March 27, 2023 @01:56AM (#35323338)
I dont know any of this but doesn't the OP give a solution similar to this https://github.com/Suor/django-cacheops
Re:Ban 1+N in Django by wruza on Monday March 27, 2023 @06:55AM (#35325084)
It’s hard to tell by skimming through the readme, but it seems there’s no mention of this technique.
Re:Ban 1+N in Django by Suor on Monday March 27, 2023 @06:58AM (#35325105)
cacheops is more of a general purpose ORM caching with automatic invalidation.