[wp-hackers] wpdb and caching

Nathaniel Taintor goldenapplesdesign at gmail.com
Mon Feb 4 21:30:23 UTC 2013


You're probably getting the number stored in the comment_count column from
the wp_posts table. To prevent having to recount comments (an expensive db
query) on the fly, the comment count is stored in the posts table and only
updated on comment-related actions (saving/approving a new comment on a
post, deleting a comment, etc.)

Look at the function wp_update_comment_count_now() to update comment counts
on all posts after doing a direct database manipuation.



Nathaniel Taintor, Designer/Developer
*Golden Apples Design*
http://goldenapplesdesign.com

@GoldenApples | 717.434.3226
goldenapplesdesign at gmail.com


On Mon, Feb 4, 2013 at 1:07 PM, Haluk Karamete <halukkaramete at gmail.com>wrote:

> This is right from the wpdb codex (
> http://codex.wordpress.org/Class_Reference/wpdb)
>
> SELECT a Row
> ... If more than one row is returned by the query, only the specified
> row is returned by the function, but all rows are cached for later
> use. ....
>
> My question is on the caching. Where is the cache kept? Are we talking
> about a mysql server cache here? Or is there a transient like
> implementation that I could not spot in the core?
>
> The reason I found myself dealing with the cache matter is because
> when I display the number of comments for the most popular posts, I'm
> stuck with the old number of comments even though I programmatically
> truncated the wp_comments and wp_commentsmeta, and there are
> absolutely no records in those tables, but yet, I still see numbers
> like 1,175 comments on display.
>
> I do not have any caching plugins to blame. And the theme that I'm
> using is using the plain old
>
> comments_popup_link(__('No Comment','source'), __('1
> Comment','source'), __('% Comments','source')); code.
>
> What could be the reason of getting a display of old number of
> comments on the display?
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list