mirror of
https://github.com/discourse/discourse.git
synced 2025-05-24 03:36:18 +08:00
DEV: Prefer nested queries (#23464)
Some sites have a large number of categories and fetching the category IDs or category topic IDs just to build another query can take a long time or resources (i.e. memory).
This commit is contained in:
@ -569,8 +569,7 @@ class Topic < ActiveRecord::Base
|
||||
topics = topics.limit(opts[:limit]) if opts[:limit]
|
||||
|
||||
# Remove category topics
|
||||
category_topic_ids = Category.pluck(:topic_id).compact!
|
||||
topics = topics.where("topics.id NOT IN (?)", category_topic_ids) if category_topic_ids.present?
|
||||
topics = topics.where.not(id: Category.select(:topic_id).where.not(topic_id: nil))
|
||||
|
||||
# Remove muted and shared draft categories
|
||||
remove_category_ids =
|
||||
|
Reference in New Issue
Block a user