I have a ten minute long video where people can stop the video and leave comments. The time (in seconds) and the comment are both saved in the database. There can be multiple comments left at the same second.
When there is a comment available to be viewed, an icon is displayed. I am using a 10 second window so a comment left at 8 seconds will be available from 3 - 13 seconds.
I am currently polling the database every 2 seconds with
SELECT COUNT(*) AS count FROM comments WHERE time BETWEEN $time-5 AND $time+5
When somebody clicks the icon to view the comments, I retrieve the relevant comments from the database.
Would it be better - performance wise - to get all the comments at the beginning, build some sort of javascript object or array, and iterate over the objects with a custom between method?
I know it depends on how many comments I am working with but I don't want to go through the hassle of building the javascript solution and running performance tests if the MySQL COUNT queries are inconsequential.