A platform for community discussion. Free, open, simple.
optimize query for fetching PM created in previous hour
Arpit Jalan345b453ee1af
diff --git a/lib/topic_view.rb b/lib/topic_view.rbindex 68aac048746..8217aaa9304 100644--- a/lib/topic_view.rb+++ b/lib/topic_view.rb@@ -496,8 +496,7 @@ class TopicViewraise Discourse::InvalidAccess.new("can't see #{@topic}", @topic) unless @guardian.can_see?(@topic)# log personal message viewsif 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)endend