I’ve created a Model called “PostView”. Each time a user views a post, it logs it into the database (creating a new record with the user id and post id).
I’m only wanting to retain 10 records per user in the DB. So each time a new record is added, I want to remove all but the latest 10 records.
- Is this efficient? If not, what do you suggest as a way to log user/post views?
- How can I add the new record and delete all but the latest 10 records in Rails?
Thanks!
It seems like this will cause a lot of overhead and that you’d be better off pruning the database via cron on some regular basis or if you really only need the last 10 records, find a more efficient way to store them. But if you can’t do that…