mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 11:15:05 +08:00
optimize query for fetching PM created in previous hour
This commit is contained in:
parent
8229cc2ff1
commit
345b453ee1
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user