Skip to content

Commit 191325e

Browse files
authored
Merge branch 'develop' into 0valt/1790/preferences
2 parents fb7fccb + c86ab29 commit 191325e

5 files changed

Lines changed: 14 additions & 6 deletions

File tree

app/controllers/application_controller.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,10 @@ def pull_pinned_links_and_hot_questions
259259
.order('score DESC').limit(SiteSetting['HotQuestionsCount']).all
260260
end
261261
end
262+
263+
# eager loading revived collections' used relation to prevent N+1 queries
264+
@pinned_links = @pinned_links.list_includes
265+
@hot_questions = @hot_questions.list_includes
262266
end
263267

264268
def pull_categories

app/controllers/categories_controller.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,10 @@ def set_list_posts
167167
SiteSetting['LotteryAgeDeprecationSpeed']],
168168
native: Arel.sql('att_source IS NULL DESC, last_activity DESC') }
169169
sort_param = sort_params[params[:sort]&.to_sym] || { last_activity: :desc }
170-
@posts = @category.posts.undeleted.where(post_type_id: @category.display_post_types)
171-
.includes(:post_type, :tags).list_includes
170+
@posts = @category.posts
171+
.undeleted
172+
.where(post_type_id: @category.display_post_types)
173+
.list_includes
172174
filter_qualifiers = helpers.params_to_qualifiers(params)
173175
@active_filter = helpers.active_filter
174176

app/models/pinned_link.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ class PinnedLink < ApplicationRecord
22
include MaybeCommunityRelated
33
belongs_to :post, optional: true
44

5+
scope :list_includes, lambda {
6+
includes(:post, post: [:community])
7+
}
8+
59
validate :check_post_or_url
610

711
# Is the link time-constrained?

app/models/post.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ class Post < ApplicationRecord
5151
scope :parent_by, ->(user) { includes(:parent).where(parents_posts: { user_id: user.id }) }
5252
scope :qa_only, -> { where(post_type_id: [Question.post_type_id, Answer.post_type_id, Article.post_type_id]) }
5353
scope :list_includes, lambda {
54-
includes(:user, :tags, :post_type, :category, :last_activity_by,
54+
includes(:user, :tags, :post_type, :category, :community, :last_activity_by,
55+
category: [:moderator_tags, :required_tags, :topic_tags],
5556
user: :avatar_attachment)
5657
}
5758
scope :has_duplicates, -> { joins(:inbound_duplicates) } # uses INNER JOIN by default so no where required

app/views/posts/_list.html.erb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
<%# is_question = post.post_type_id == Question.post_type_id %>
2-
<%# is_article = post.post_type_id == Article.post_type_id %>
3-
<%# is_meta = (is_question && post.meta?) || (!is_question && post.parent&.meta?) %>
41
<% @show_type_tag = !!defined?(show_type_tag) ? show_type_tag : false %>
52
<% @show_category_tag = !!defined?(show_category_tag) ? show_category_tag : false %>
63
<% @last_activity = !!defined?(last_activity) ? last_activity : true %>

0 commit comments

Comments
 (0)