Search code examples
ruby-on-railsruby-on-rails-4counter-cacheimpressions

Rails 4, Impressionist and counter_cache


I have a Post model which I've made impressionable:

is_impressionable :counter_cache => true, :column_name => :views

I was thinking about, let's say once a month, clearing impressions older than a given period. Would this somehow reset the counters cache in the posts table too ? In this case, is there any solution ( increment only counter cache ? ) to avoid the impressions table growing bigger and bigger until it goes out of control without resetting the counters ?

Thanks


Solution

  • You cannot remove impressions from the impressions table, because every time the cache needs to be updated, impressionist will actually recount all the impressions (filtered by the unique option you're providing is_impressionable).

    I'm not sure what you can do with the gem to achieve what you want, except patching it, or managing the counter_cache yourself.