codyseibert / tab-tracker

A Vue.js / Express.js web application for keeping track of guitar tabs
MIT License
522 stars 197 forks source link

prevent duplicate songs in recently viewed songs table and maintain sort based on view order #27

Closed jdkoeh79 closed 6 years ago

jdkoeh79 commented 6 years ago

I added a ViewCount column to the database history table. When a user views a song and posts to the histories controller, before inserting a new row, the database is queried to see if a history entry already exists for this user/song. If one is found, the existing entry's view count is incremented by one, automatically modifying the UpdatedAt timestamp, which is what is used to sort the history table on the view.

jdkoeh79 commented 6 years ago

This actually doesn't change the functionality of the page at all and only serves to prevent duplicate user/song entries in the history table, which in a real world application, you might want for analytical reasons. You could display the view count to the user, but you don't need to explicitly store it, counting the results of a db selectAll for that user/song would get you that value. At least I learned how to do a pull request!