mirror of
https://github.com/discourse/discourse.git
synced 2024-12-05 10:53:44 +08:00
5cfe323445
What is this change required? I noticed that actions in `SidebarSectionsController` resulted in lots of N+1 queries problem and I wanted a solution to prevent such problems without having to write N+1 queries tests. I have also used strict loading for `SidebarSection` queries in performance sensitive spots. Note that in this commit, I have also set `config.active_record.action_on_strict_loading_violation = :log` for the production environment so that we have more visibility of potential N+1 queries problem in the logs. In development and test environment, we're sticking with the default of raising an error.
14 lines
318 B
Ruby
14 lines
318 B
Ruby
# frozen_string_literal: true
|
|
|
|
class SidebarSectionSerializer < ApplicationSerializer
|
|
attributes :id, :title, :links, :slug, :public, :section_type
|
|
|
|
def links
|
|
object.sidebar_urls.map { |sidebar_url| SidebarUrlSerializer.new(sidebar_url, root: false) }
|
|
end
|
|
|
|
def slug
|
|
object.title.parameterize
|
|
end
|
|
end
|