From 09e470c98a0021dce1b9c1ac595f8340e7ff26d8 Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 5 Mar 2015 15:25:05 +1100 Subject: [PATCH] FEATURE: start counting repeat topic views (default is one per 8 hours) configurable with topic_view_duration_hours site setting --- app/models/topic_view_item.rb | 5 +++-- config/locales/server.en.yml | 1 + config/site_settings.yml | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/models/topic_view_item.rb b/app/models/topic_view_item.rb index 6f5ca40c367..215ad9f72e5 100644 --- a/app/models/topic_view_item.rb +++ b/app/models/topic_view_item.rb @@ -16,7 +16,7 @@ class TopicViewItem < ActiveRecord::Base end if skip_redis || $redis.setnx(redis_key, "1") - skip_redis || $redis.expire(redis_key, 1.day.to_i) + skip_redis || $redis.expire(redis_key, SiteSetting.topic_view_duration_hours.hours) TopicViewItem.transaction do at ||= Date.today @@ -40,8 +40,9 @@ class TopicViewItem < ActiveRecord::Base result = builder.exec(topic_id: topic_id, ip_address: ip, viewed_at: at, user_id: user_id) + Topic.where(id: topic_id).update_all 'views = views + 1' + if result.cmd_tuples > 0 - Topic.where(id: topic_id).update_all 'views = views + 1' UserStat.where(user_id: user_id).update_all 'topics_entered = topics_entered + 1' if user_id end diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 1efc98cb66b..fa23184bd1f 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -1024,6 +1024,7 @@ en: white_listed_spam_host_domains: "A list of domains excluded from spam host testing. New users will never be restricted from creating posts with links to these domains." staff_like_weight: "How much extra weighting factor to give staff likes." + topic_view_duration_hours: "Count new a topic view once per IP/User every N hours" levenshtein_distance_spammer_emails: "When matching spammer emails, number of characters difference that will still allow a fuzzy match." max_new_accounts_per_registration_ip: "If there are already (n) trust level 0 accounts from this IP (and none is a staff member or at TL2 or higher), stop accepting new signups from that IP." diff --git a/config/site_settings.yml b/config/site_settings.yml index 1b4483a12d2..c2fa4cc6aa3 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -750,6 +750,7 @@ uncategorized: new_topic_duration_minutes: 2880 previous_visit_timeout_hours: 1 staff_like_weight: 3 + topic_view_duration_hours: 8 # Summary mode summary_score_threshold: 15