I’m with you — and of course agree all your reasons are extremely legit. some quick notes back at ya (since we help the populace learn by tossing out examples):
for (1): I’ve seen cases where people were re-opening connections to the db — I noted that just for clarity, not that you were! ??
for (2): there’s likely more overhead to the SQL lookup itself. also, as I mentioned I’ve got db debug stuff, which basically tracks every query call coming through wpdb including a string name of caller, good for tracking too-many-queries or not-enough-caching. ??
and for (3): all the more reason to enhance wpdb to expose needed functionality! ?? In addition to coding guidelines (some of which I don’t agree with, especially some of the formatting! ?? ), it also forwards the ability to remove dependence on MySQL in the future… ?? Almost worth starting a new topic on enhancing wpdb for that reason alone…
I just basically cloned your idea but embedded into the posts table. One update query does the +1, the count is already in $post when needed, and popular posts queries one db. But again, that’s great for someone like me who’s already hacked up the tables — for 99% of users out there, your approach wins hands down, no question… well, and I haven’t tested mine yet.
Bitch that I didn’t have this in place two months ago — reconstructing counts from referrer log wasn’t overly useful, as it’s easily missing dozens or even hundreds of views… but gotta start somewhere!
By the way Mark, want to reinforce again cool idea and sample! Keeps me thinking about methods for enhancing my site, and continues to push me to learn more SQL tricks. ?? Keep up the good work!
-d
https://www.chait.net