FIX: Use custom date for redis key in `TopicViewItem.add`.
This commit is contained in:
parent
d39faf7ddf
commit
5fb405cca2
|
@ -8,7 +8,8 @@ class TopicViewItem < ActiveRecord::Base
|
||||||
|
|
||||||
def self.add(topic_id, ip, user_id=nil, at=nil, skip_redis=false)
|
def self.add(topic_id, ip, user_id=nil, at=nil, skip_redis=false)
|
||||||
# Only store a view once per day per thing per user per ip
|
# Only store a view once per day per thing per user per ip
|
||||||
redis_key = "view:#{topic_id}:#{Date.today}"
|
at ||= Date.today
|
||||||
|
redis_key = "view:#{topic_id}:#{at}"
|
||||||
if user_id
|
if user_id
|
||||||
redis_key << ":user-#{user_id}"
|
redis_key << ":user-#{user_id}"
|
||||||
else
|
else
|
||||||
|
@ -19,8 +20,6 @@ class TopicViewItem < ActiveRecord::Base
|
||||||
skip_redis || $redis.expire(redis_key, SiteSetting.topic_view_duration_hours.hours)
|
skip_redis || $redis.expire(redis_key, SiteSetting.topic_view_duration_hours.hours)
|
||||||
|
|
||||||
TopicViewItem.transaction do
|
TopicViewItem.transaction do
|
||||||
at ||= Date.today
|
|
||||||
|
|
||||||
# this is called real frequently, working hard to avoid exceptions
|
# this is called real frequently, working hard to avoid exceptions
|
||||||
sql = "INSERT INTO topic_views (topic_id, ip_address, viewed_at, user_id)
|
sql = "INSERT INTO topic_views (topic_id, ip_address, viewed_at, user_id)
|
||||||
SELECT :topic_id, :ip_address, :viewed_at, :user_id
|
SELECT :topic_id, :ip_address, :viewed_at, :user_id
|
||||||
|
|
Loading…
Reference in New Issue