mirror of
https://github.com/discourse/discourse.git
synced 2025-04-29 15:14:39 +08:00
PERF: eliminate N+1 query due to polls
This commit is contained in:
parent
374e7325fa
commit
c3e3afcb2c
@ -433,7 +433,14 @@ class TopicView
|
|||||||
end
|
end
|
||||||
|
|
||||||
def closest_post_to(post_number)
|
def closest_post_to(post_number)
|
||||||
|
# happy path
|
||||||
|
closest_post = @filtered_posts.where("post_number = ?", post_number).limit(1).pluck(:id)
|
||||||
|
|
||||||
|
if closest_post.empty?
|
||||||
|
# less happy path, missing post
|
||||||
closest_post = @filtered_posts.order("@(post_number - #{post_number})").limit(1).pluck(:id)
|
closest_post = @filtered_posts.order("@(post_number - #{post_number})").limit(1).pluck(:id)
|
||||||
|
end
|
||||||
|
|
||||||
return nil if closest_post.empty?
|
return nil if closest_post.empty?
|
||||||
|
|
||||||
filtered_post_ids.index(closest_post.first) || filtered_post_ids[0]
|
filtered_post_ids.index(closest_post.first) || filtered_post_ids[0]
|
||||||
|
@ -14,6 +14,15 @@ VOTES_CUSTOM_FIELD ||= "polls-votes".freeze
|
|||||||
|
|
||||||
after_initialize do
|
after_initialize do
|
||||||
|
|
||||||
|
# PERF, avoids N+1 in serializer
|
||||||
|
TopicView.add_post_custom_fields_whitelister do |user|
|
||||||
|
POLLS_CUSTOM_FIELD
|
||||||
|
end
|
||||||
|
|
||||||
|
TopicView.add_post_custom_fields_whitelister do |user|
|
||||||
|
VOTES_CUSTOM_FIELD
|
||||||
|
end
|
||||||
|
|
||||||
# remove "Vote Now!" & "Show Results" links in emails
|
# remove "Vote Now!" & "Show Results" links in emails
|
||||||
Email::Styles.register_plugin_style do |fragment|
|
Email::Styles.register_plugin_style do |fragment|
|
||||||
fragment.css(".poll a.cast-votes, .poll a.toggle-results").each(&:remove)
|
fragment.css(".poll a.cast-votes, .poll a.toggle-results").each(&:remove)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user