2 ms·
I don't know, but I do know that my architectural approach is to get any web app I write to only hit the database ONCE per page view. Ten calls is a lot for me.
by silverbax88 15y ago
I don't know, but I do know that my architectural approach is to get any web app I write to only hit the database ONCE per page view. Ten calls is a lot for me. I've seen some that hit the DB 100 times on each view and I was able to reduce all 100 down to a single call.
- kalleboo 15y agoLess queries isn't always better. Sometimes a couple small fast (easily optimized by the DB server) queries are faster than a join (which could block several tables at once instead of just one).
- silverbax88 15y agoThis is true; you have to decide when that is. Of course, multiple queries across tables can be placed into a view and queried at once.
- pestaa 15y agoI heard one specific Joomla site used 800 queries to render the front page. A dev needs natural talent to reach that point, I guess.
- arghnoname 15y agoI worked on a site once that loaded at an okay rate for the live site, but the staging server would take about 15 minutes (seriously) to load once every other hour or so. I thought this was strange, same code and all, so I looked into it. There was a loop on the page that instantiated objects with an id, the number of ids dependent on the results of a previous query. What did that object instantiation do under the hood? It performed a query to fetch state. I calculated that 5000 queries were being run, and it only cropped up every once and a while (and seemingly 'never' on the live site) because queries were automatically cached for a set amount of time. I was new on the project, and in what is probably poor form, went around the whole office, letting my horror be fully known. People just shrugged though. edit: I forgot to add, modifying it to only perform one query was trivial.