From c6c4169ae3507f9f0cad0f1e657f60866619f66e Mon Sep 17 00:00:00 2001 From: joshua stein Date: Sun, 16 Dec 2012 18:46:38 -0600 Subject: [PATCH] don't count spider traffic towards traffic counter --- app/controllers/application_controller.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index b709c7f..95b1ff6 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -16,6 +16,10 @@ class ApplicationController < ActionController::Base def increase_traffic_counter @traffic = 1.0 + if user_is_spider? + return true + end + Keystore.transaction do date = (Keystore.value_for("traffic:date") || Time.now.to_i) traffic = (Keystore.incremented_value_for("traffic:hits", 0). @@ -50,4 +54,8 @@ class ApplicationController < ActionController::Base return false end end + + def user_is_spider? + !!request.env["HTTP_USER_AGENT"].to_s.match(/Googlebot/) + end end