From 3a35f459c781f38143936674376f348df45a30bc Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Sun, 11 Mar 2018 09:34:08 +0530 Subject: [PATCH] optimize last pm log fetching --- lib/topic_view.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/topic_view.rb b/lib/topic_view.rb index b55734b7550..68aac048746 100644 --- a/lib/topic_view.rb +++ b/lib/topic_view.rb @@ -496,7 +496,7 @@ class TopicView raise Discourse::InvalidAccess.new("can't see #{@topic}", @topic) unless @guardian.can_see?(@topic) # log personal message views 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 StaffActionLogger.new(@user).log_check_personal_message(@topic) end