impressionist icon indicating copy to clipboard operation
impressionist copied to clipboard

Will I be able to periodically clear impressions table ?

Open evilsocket opened this issue 11 years ago • 8 comments

Hi there, 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 to avoid the impressions table growing bigger and bigger until it goes out of control ?

Thanks

evilsocket avatar Oct 20 '13 23:10 evilsocket

Hi @evilsocket , Thanks for pointing this out. So far there's no way to do so. However impressionist 2.0 rc1 I will implement such a thing. Any thoughts how we'd implement it?

Thanks, Nalesso Antonio

acnalesso avatar Oct 28 '13 20:10 acnalesso

Thanks for your response. Well, considering this is something related to the counter_cache mechanism ( I'm a new entry in the Rails world, so I may be wrong ) which performs exactly the same ( delete all records = counter_cache to 0 ), I guess your only choice is to increase only the counter performing a comparision, if you get a value which is less than the actual one you will just skip the operation ...

evilsocket avatar Oct 28 '13 20:10 evilsocket

I have thought about that, I am developing Impressionist 2.0.rc1 with a In-process queue, so that it would be able to fetch all saved impressions count them and then update_counters without blocking IO. However this would work temporary as impressions start growing it would be an issue and we wouldn't be fixing the 'cancer' but only the symptom. I also thought of backing up everything and storing them somewhere just in case one needs to have a look at those saved impressions and then start counting over again. So that we would to come with a default number of impressions to be saved, then back them up.... All these solutions doesn't seem the right way to solve this.

acnalesso avatar Oct 28 '13 21:10 acnalesso

another column ? backed_views and views ... the first one is set to 0 at the beginning and updated only when impression records get deleted, so I could order by both ... you know I need this not only for historical data, I use the views column ( an alias to impressions ) to compute the popular snippets on http://www.emoticode.net/ ... something like ORDER BY views / days_of_the_snippet ... having the views column set to 0 would mean bogus rankings for my website.

evilsocket avatar Oct 28 '13 21:10 evilsocket

I think it would be a great addition if we were able to update :counter_cache based on a :start_date. So data could be sorted based on recent impressions.

maikelfb avatar Apr 02 '14 13:04 maikelfb

Any news on this ?

Also I'm wondering if I clear the impressions table, will all the counter_caches reset too ? I mean are the counter_caches re-counting from the impressions table each time or just incrementing ?

jerefrer avatar Jun 16 '15 10:06 jerefrer

@jerefrer I think so. I just cleared the impressions table and the counter_cache of one of my model was reset to Zero.

sjayanna avatar Oct 12 '15 22:10 sjayanna

This feature is very helpful for me, need to periodically clean Impression table, BTW, how do we do Unique visitor definition? let's say normally in monthly, if we clean up the data month ago can we say it is Unique monthly visitors?

pChaAnthony avatar Aug 09 '17 14:08 pChaAnthony