optimize last pm log fetching

This commit is contained in:
Arpit Jalan 2018-03-11 09:34:08 +05:30
parent f862122978
commit 3a35f459c7
1 changed files with 1 additions and 1 deletions

View File

@ -496,7 +496,7 @@ class TopicView
raise Discourse::InvalidAccess.new("can't see #{@topic}", @topic) unless @guardian.can_see?(@topic) raise Discourse::InvalidAccess.new("can't see #{@topic}", @topic) unless @guardian.can_see?(@topic)
# log personal message views # log personal message views
if SiteSetting.log_personal_messages_views && @topic.present? && @topic.private_message? && @topic.all_allowed_users.where(id: @user.id).blank? if SiteSetting.log_personal_messages_views && @topic.present? && @topic.private_message? && @topic.all_allowed_users.where(id: @user.id).blank?
last_pm_log = UserHistory.where(acting_user_id: @user.id, action: UserHistory.actions[:check_personal_message], topic_id: @topic.id).last last_pm_log = UserHistory.where(acting_user_id: @user.id, action: UserHistory.actions[:check_personal_message], topic_id: @topic.id).order(created_at: :desc).first
unless last_pm_log.present? && last_pm_log.created_at > 1.hour.ago unless last_pm_log.present? && last_pm_log.created_at > 1.hour.ago
StaffActionLogger.new(@user).log_check_personal_message(@topic) StaffActionLogger.new(@user).log_check_personal_message(@topic)
end end