4 ms·
A few milliseconds per query adds up if you're doing one query per item in a list with 100s or 1000s of elements :)
by augustl 3y ago
A few milliseconds per query adds up if you're doing one query per item in a list with 100s or 1000s of elements :)
- robertlagrant 3y ago> A few milliseconds per query adds up if you're doing one query per item in a list with 100s or 1000s of elements :) If you're doing this, then you need to stop :)
- tyre 3y agoah okay. in that case add in a couple hours to refactor those N+1 queries and you’re all good
- bt1a 3y agowhen do you ever have to do one query per array of items? genuinely curious
- augustl 3y agoI suppose I think of this the other way around. When the query engine is inside your app, the query engine doesn't need to do loop-like things. So you can have a much simpler querying language and mix it with plain code, kind of similar to how you don't need a templating language in React (and in Clojure when you use hiccup to represent HTML) Additionally, this laziness means your business logic can dynamically choose which data to pull in based on results of queries, and you end up with running fewer queries as you'll never need to pull in extra data in one huge query in case business logic needs it.