Can you help me solve a potential performance problem with Ferret and view counts

I am currently using Ferret and the DRb server for search and can forsee a potential problem which I am hoping some of you good folks can help me with.

I currently have a view count field associated with a record, which is incremented every time the view for the record is displayed.

This field is part of the search index such that we can search and sort by the "most viewed" records.

The potential performance issue is that each time the page is viewed, the counter is incremented, and this triggers the index to be rebuilt for the associated record.

I have considered disabling the after_save callbacks method but feel this is taking a hammer to the problem, as in most cases I do need the index to be updated immediately after the record is updated.

I am assuming implementing a view count and using for search is not an uncommon requirement... so hoping there is a good solution.

Thanks Roderick...one question... since I still do want to include the view count in the index... does that imply a periodic CRON job for updating this field within the Ferret index? Is there a way to rebuild only a subset of the fields within the index?

Hi Jamie,

Thanks Roderick...one question... since I still do want to include the view count in the index... does that imply a periodic CRON job for updating this field within the Ferret index? Is there a way to rebuild only a subset of the fields within the index?

I don't believe that it's possible to update a subset of columns: the other indexed columns would then be set to nil. Performance would not improve that much because the indexed row needs to be rewritten anyway.

So yes, a periodic update on the entire object would suffice if you don't require real-time counts in the index.

Hi Jamie,

I really wouldn't use ferret for this. Use the DB to show the most viewed...

Cheers, Sazima

Can you put the counts in their own table, with foreign keys to the original record?

Then you need only issue the update to that model…

c = Counter.find_by_thing_id(25) c.count +=1

c.save

just thinking out loud.