mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 23:58:31 -05:00
let's not run 3 queries, when a single query will do.
This commit is contained in:
parent
7661a5fed2
commit
8ec6d0ea6c
1 changed files with 9 additions and 7 deletions
|
@ -12,17 +12,19 @@ class SuggestedTopicsBuilder
|
||||||
|
|
||||||
def add_results(results)
|
def add_results(results)
|
||||||
|
|
||||||
return if results.blank?
|
# WARNING .blank? will execute an Active Record query
|
||||||
|
return unless results
|
||||||
|
|
||||||
# Only add results if we don't have those topic ids already
|
# Only add results if we don't have those topic ids already
|
||||||
results = results.where('topics.id NOT IN (?)', @excluded_topic_ids)
|
results = results.where('topics.id NOT IN (?)', @excluded_topic_ids)
|
||||||
.where(closed: false, archived: false, visible: true)
|
.where(closed: false, archived: false, visible: true)
|
||||||
|
.to_a
|
||||||
|
|
||||||
return if results.blank?
|
unless results.empty?
|
||||||
|
# Keep track of the ids we've added
|
||||||
# Keep track of the ids we've added
|
@excluded_topic_ids.concat results.map {|r| r.id}
|
||||||
@excluded_topic_ids.concat results.map {|r| r.id}
|
@results.concat results
|
||||||
@results.concat results
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def results_left
|
def results_left
|
||||||
|
@ -37,4 +39,4 @@ class SuggestedTopicsBuilder
|
||||||
@results.size
|
@results.size
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue