I'm using Ahoy with Mongoid store. Any advice is much appreciated!
My issue is that, for efficiency's sake, every time a new ahoy event is created, I want to update that elements count so I can do stuff like sorting by pageviews. My plan was to use a mongoid callback like after_create to update a counter everytime an event is generated. something like:
class Ahoy::Event
after_create :update_pageviews
def update_pageviews
case self.name
when 'Viewed post'
p = Monologue::Post.find(properties[:post])
p.pageviews = p.pageviews + 1
p.save
end
end
however, the callback never seems to even get fired.
- Is there a better way to handle this? Pulling the counts live is too slow for me, so I need to store it somewhere.
- Why isn't the callback firing?