| ▲ | sgt a day ago | |||||||
I mean if you're doing it this way, you're really not applying best practices as a developer (never mind as a Django developer). > Models being passed around everywhere, queries happening everywhere. No, as a developer you still need to be 100% aware of the underlying queries and potential performance issues. No excuse for N+1 problems. ORM is not an excuse to be lazy, but I admit it will probably catch quite a few developers. Those same developers would probably make a mess out of any other framework or technology though. | ||||||||
| ▲ | thraxil 13 hours ago | parent | next [-] | |||||||
The other thing that I think people tend to forget is that there are plenty of situations where N+1 queries just aren't that big a deal. Not every view in every application that every developer builds needs to handle massive amounts of traffic with low latency and high cardinality tables. I've built so many apps where there's one or two users, small amounts of data, etc. And even on apps that do have a lot of traffic, there are often internal/admin/maintenance views that don't have the same requirements and no one will notice an N+1 where N = 5 in the worst possible case. Every time ORMs get discussed, it seems to be dominated by people who are like "but my app has 5 billion concurrent users doing 2 million requests per second and if there's an extra 5ms on my requests, it will all explode!" and can't comprehend that not everyone is building the same kind of systems all the time. Great, maybe an ORM isn't appropriate for your situation. | ||||||||
| ||||||||
| ▲ | strogonoff a day ago | parent | prev [-] | |||||||
Django allowing queries to be anywhere is more or less in line with Python’s overarching “we’re all consenting adults here” ethos. There’s probably one correct way to do it, but if you want to shoot yourself in the foot then here’s your gun. It definitely takes a bit of discipline. The key layers are somewhat easy to manage—middleware, context processors, views, template tags—but I’ve seen some hairy lasagne further obscuring where the queries happen on top of that. A well-documented abstraction can be useful, but if it is possible to keep it simple and obvious then that’s the way to go. (Third-party dependencies can further complicate things, but at least you can expect a library using ORM to be in the installed apps list.) | ||||||||
| ||||||||