FIX: Topic reset_new unscoped causing huge queries (PR #14158)

Since ad3ec5809faf2cb9553b0c530967bbd1eb5c58ed when a user chooses the Dismiss New… option in the New topic list, we send a request to topics/reset-new.json with ?tracked=false as the only parameter.

This then uses Topic as the scope for topics to dismiss, with no other limitations. When we do topic_scope.pluck(:id), it gets the ID of every single topic in the database (that is not deleted) to pass to TopicsBulkAction, causing a huge query with severe performance issues.

This commit changes the default scope to use TopicQuery.new(current_user).new_results(limit: false) which should only use the topics in the user’s New list, which will be a much smaller list, depending on the user’s “new_topic_duration_minutes” setting.

See also Select Dismissal Unexpected Behavior - support - Discourse Meta

GitHub