From 17f0727b0409ca92001c78a7b8d954c83d94121a Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Tue, 23 Aug 2016 16:25:31 +0800 Subject: [PATCH] FIX: Don't track user profile view when viewed by system user. --- app/models/user_profile_view.rb | 1 + spec/models/user_profile_view_spec.rb | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/app/models/user_profile_view.rb b/app/models/user_profile_view.rb index 2fd3cd1c2..efe43cd42 100644 --- a/app/models/user_profile_view.rb +++ b/app/models/user_profile_view.rb @@ -7,6 +7,7 @@ class UserProfileView < ActiveRecord::Base at ||= Time.zone.now redis_key = "user-profile-view:#{user_profile_id}:#{at.to_date}" if user_id + return if user_id < 1 redis_key << ":user-#{user_id}" else redis_key << ":ip-#{ip}" diff --git a/spec/models/user_profile_view_spec.rb b/spec/models/user_profile_view_spec.rb index 66474b7e0..8c4f8a56d 100644 --- a/spec/models/user_profile_view_spec.rb +++ b/spec/models/user_profile_view_spec.rb @@ -36,4 +36,9 @@ RSpec.describe UserProfileView do expect(described_class.count).to eq(1) end end + + it "should not create a profile view for the system user" do + add(user_profile_id, '1.1.1.1', Discourse::SYSTEM_USER_ID) + expect(described_class.count).to eq(0) + end end