Mohammad A. wrote:
I’m thinking of creating a model called ‘product_view’ which has
product_id & view_counter, and updating this table in product#show.
This sounds like a fine plan, but does it provide any advantage over
simply adding a view_count attribute to your product model?
In either case you must update the database on every product view.
Putting the column right on the product model seems to be a simpler
solution to me. This way you don’t have to mess with any model
Having a separate table to store your counts would, technically, be a
more efficient use of disk space. But, as you said you expect around
30,000 products. This is a pretty small number in the grand scheme of
things so I wouldn’t be worried much about the extra space one more
integer column would take. Certainly not enough to warrant the addition
of a separate model.