Foo
Foo

Reputation: 810

How can I check if counter cache is working okay?

I've done everything what it says on Railscast( http://railscasts.com/episodes/23-counter-cache-column ).

I've done with those setups

and I have this in my view

<%= community_topic.comment_threads.size %>

As you know, I can't see any difference on its appearance.
How can I know if counter cache is working fine now?

Upvotes: 0

Views: 711

Answers (1)

Andrew Marshall
Andrew Marshall

Reputation: 96994

As it says in the RailsCast you reference, you should verify by checking the SQL that is being run via the logs. Before the counter cache you should get a SQL COUNT query something like this:

SELECT count(*) AS count_all FROM "comment_threads" WHERE ("comment_threads".commentable_id = 61)

and after you should not see one, and instead only see the CommunityTopic loading:

SELECT * FROM "comment_threads" WHERE id = 61

Upvotes: 2

Related Questions