optimize query for fetching PM created in previous hour

This commit is contained in:
Arpit Jalan 2018-03-12 16:40:17 +05:30
parent 8229cc2ff1
commit 345b453ee1

View File

@ -496,8 +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).order(created_at: :desc).first
unless last_pm_log.present? && last_pm_log.created_at > 1.hour.ago
unless UserHistory.where(acting_user_id: @user.id, action: UserHistory.actions[:check_personal_message], topic_id: @topic.id).where("created_at > ?", 1.hour.ago).exists?
StaffActionLogger.new(@user).log_check_personal_message(@topic)
end
end