# Calculate Page views efficiently

**URL:** <https://www.ruby-forum.com/t/calculate-page-views-efficiently/158848>\
**Category:** Rails\
**Created:** [January 28, 2009, 7:04pm UTC](https://www.ruby-forum.com/t/calculate-page-views-efficiently/158848 "2009-01-28T19:04:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [January 28, 2009, 7:04pm UTC](https://www.ruby-forum.com/t/calculate-page-views-efficiently/158848/1 "2009-01-28T19:04:27Z")

</div>

Hi,  
I am coding forum software in rails. In forum software how many  
times a thread is viewed is an important metric .one way of doing this  
is creating a before\_filter which logs in a view everytime a page is  
requested.

actually just because i need to run this before\_filter i can’t do page  
caching which can drastically improve the performance of the app. can  
anyone suggest a better way of logging views of every thread.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [January 28, 2009, 7:15pm UTC](https://www.ruby-forum.com/t/calculate-page-views-efficiently/158848/2 "2009-01-28T19:15:34Z")

</div>

Maybe with a distinct insert into a history table? thread\_views  
(thread\_id int, view\_count) outside of the before\_filter… somewhere  
else?

Or parsing of the logs?

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [January 28, 2009, 8:13pm UTC](https://www.ruby-forum.com/t/calculate-page-views-efficiently/158848/3 "2009-01-28T20:13:12Z")

</div>

sullivan,  
thanks for the reply. But the very act of inserting into  
any table means i cannot use page caching which will be aserious  
performance penalty to pay.

i will explore the logs option though. thanks

Cheers,  
Deepu.
