Skip to content

View Count

K Sashi Kumar edited this page Jul 23, 2017 · 1 revision

Implementation of View count

Forli tracks view count of Discussion and Answer. If for each view, we update the value in the database, there will be an update query of each visit to the page. This would not scale better. So, in Forli, the view counts are batch updated to the database. This means that values are stored in Redis till a threshold is reached. The batch threshold in Forli is 100. While reading the view count, an additional redis query is fired to get the transient count in redis. By doing batch update, there will only be 1 update query in 100 view hit requests!

The code that handles this logic can be found in: lib/meta_info/view_count.rb

The redis key that holds the values are:

  • DISCUSSION_VIEW_COUNT
  • ANSWER_VIEW_COUNT
Clone this wiki locally