FIX: TopicLinkClick: do not log IP of logged in users

This commit is contained in:
riking 2018-05-21 12:04:55 -07:00 committed by Sam
parent 24abf38d38
commit 9b0efe9c84
2 changed files with 12 additions and 2 deletions

View File

@ -7,7 +7,6 @@ class TopicLinkClick < ActiveRecord::Base
belongs_to :user
validates_presence_of :topic_link_id
validates_presence_of :ip_address
WHITELISTED_REDIRECT_HOSTNAMES = Set.new(%W{www.youtube.com youtu.be})
@ -108,6 +107,7 @@ class TopicLinkClick < ActiveRecord::Base
rate_key = "link-clicks:#{link.id}:#{args[:user_id] || args[:ip]}"
if $redis.setnx(rate_key, "1")
$redis.expire(rate_key, 1.day.to_i)
args[:ip] = nil if args[:user_id]
create!(topic_link_id: link.id, user_id: args[:user_id], ip_address: args[:ip])
end
@ -125,7 +125,7 @@ end
# user_id :integer
# created_at :datetime not null
# updated_at :datetime not null
# ip_address :inet not null
# ip_address :inet
#
# Indexes
#

View File

@ -0,0 +1,10 @@
class AllowNullIpTopicLinkClick < ActiveRecord::Migration[5.1]
def up
begin
Migration::SafeMigrate.disable!
change_column :topic_link_clicks, :ip_address, :inet, null: true
ensure
Migration::SafeMigrate.enable!
end
end
end