perf: Story.has_suggestions?
This commit is contained in:
parent
dd2e74f63a
commit
823a147ad0
|
@ -480,7 +480,13 @@ class Story < ApplicationRecord
|
|||
end
|
||||
|
||||
def has_suggestions?
|
||||
self.suggested_taggings.any? || self.suggested_titles.any?
|
||||
# perf: save the round trip on a second query, equivalent to the below:
|
||||
# self.suggested_taggings.any? || self.suggested_titles.any?
|
||||
Story.joins(:suggested_taggings, :suggested_titles)
|
||||
.where('stories.id = ? and
|
||||
(suggested_taggings.id is not null or suggested_titles.id is not null)
|
||||
', self.id)
|
||||
.exists?
|
||||
end
|
||||
|
||||
def hider_count
|
||||
|
|
Loading…
Reference in New Issue