diff --git a/Gemfile b/Gemfile index 05565e6e6..a74c6ed43 100644 --- a/Gemfile +++ b/Gemfile @@ -54,12 +54,13 @@ gem "autotuner" gem "benchmark" # indirect dependency, being removed from Ruby 3.5 stdlib so here to quash warnings group :development, :test do - gem "debug" - gem "bundler-audit", require: false gem "brakeman", require: false - gem "rubocop-rails-omakase", require: false - gem "letter_opener" + gem "bundler-audit", require: false + gem "debug" gem "faker" + gem "letter_opener" + gem "rack-mini-profiler" + gem "rubocop-rails-omakase", require: false end group :development do diff --git a/Gemfile.lock b/Gemfile.lock index d72155abb..d7a3121dc 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -384,6 +384,8 @@ GEM raabro (1.4.0) racc (1.8.1) rack (3.2.4) + rack-mini-profiler (4.0.1) + rack (>= 1.2.0) rack-session (2.1.1) base64 (>= 0.1.0) rack (>= 3.0.0) @@ -606,6 +608,7 @@ DEPENDENCIES propshaft puma (>= 5.0) queenbee! + rack-mini-profiler rails! rails_structured_logging! redcarpet diff --git a/app/controllers/boards/columns/closeds_controller.rb b/app/controllers/boards/columns/closeds_controller.rb index b9aad40b3..95e0c7126 100644 --- a/app/controllers/boards/columns/closeds_controller.rb +++ b/app/controllers/boards/columns/closeds_controller.rb @@ -2,7 +2,7 @@ class Boards::Columns::ClosedsController < ApplicationController include BoardScoped def show - set_page_and_extract_portion_from @board.cards.closed.recently_closed_first + set_page_and_extract_portion_from @board.cards.closed.recently_closed_first.preloaded fresh_when etag: @page.records end end diff --git a/app/controllers/boards/columns/not_nows_controller.rb b/app/controllers/boards/columns/not_nows_controller.rb index a65f538c4..6cb765979 100644 --- a/app/controllers/boards/columns/not_nows_controller.rb +++ b/app/controllers/boards/columns/not_nows_controller.rb @@ -2,7 +2,7 @@ class Boards::Columns::NotNowsController < ApplicationController include BoardScoped def show - set_page_and_extract_portion_from @board.cards.postponed.reverse_chronologically.with_golden_first + set_page_and_extract_portion_from @board.cards.postponed.reverse_chronologically.with_golden_first.preloaded fresh_when etag: @page.records end end diff --git a/app/controllers/boards/columns/streams_controller.rb b/app/controllers/boards/columns/streams_controller.rb index 03b48d900..d2c7d0795 100644 --- a/app/controllers/boards/columns/streams_controller.rb +++ b/app/controllers/boards/columns/streams_controller.rb @@ -2,7 +2,7 @@ class Boards::Columns::StreamsController < ApplicationController include BoardScoped def show - set_page_and_extract_portion_from @board.cards.awaiting_triage.latest.with_golden_first + set_page_and_extract_portion_from @board.cards.awaiting_triage.latest.with_golden_first.preloaded fresh_when etag: @page.records end end diff --git a/app/controllers/boards/columns_controller.rb b/app/controllers/boards/columns_controller.rb index 1648da401..fa4f3e072 100644 --- a/app/controllers/boards/columns_controller.rb +++ b/app/controllers/boards/columns_controller.rb @@ -4,7 +4,7 @@ class Boards::ColumnsController < ApplicationController before_action :set_column, only: %i[ show update destroy ] def show - set_page_and_extract_portion_from @column.cards.active.latest.with_golden_first + set_page_and_extract_portion_from @column.cards.active.latest.with_golden_first.preloaded fresh_when etag: @page.records end diff --git a/app/controllers/notifications_controller.rb b/app/controllers/notifications_controller.rb index d188e3a1e..8adb04b3c 100644 --- a/app/controllers/notifications_controller.rb +++ b/app/controllers/notifications_controller.rb @@ -1,7 +1,7 @@ class NotificationsController < ApplicationController def index - @unread = Current.user.notifications.unread.ordered unless current_page_param - set_page_and_extract_portion_from Current.user.notifications.read.ordered + @unread = Current.user.notifications.unread.ordered.preloaded unless current_page_param + set_page_and_extract_portion_from Current.user.notifications.read.ordered.preloaded respond_to do |format| format.turbo_stream if current_page_param # Allows read-all action to side step pagination diff --git a/app/helpers/accesses_helper.rb b/app/helpers/accesses_helper.rb index 01aa57b7c..e52aa8ede 100644 --- a/app/helpers/accesses_helper.rb +++ b/app/helpers/accesses_helper.rb @@ -27,7 +27,7 @@ module AccessesHelper end def board_watchers_list(board) - watchers = board.watchers + watchers = board.watchers.with_avatars displayed_watchers = watchers.limit(MAX_DISPLAYED_WATCHERS) overflow_count = watchers.count - MAX_DISPLAYED_WATCHERS diff --git a/app/models/card.rb b/app/models/card.rb index cdbb08b52..ff0ae1dd5 100644 --- a/app/models/card.rb +++ b/app/models/card.rb @@ -19,8 +19,8 @@ class Card < ApplicationRecord scope :reverse_chronologically, -> { order created_at: :desc, id: :desc } scope :chronologically, -> { order created_at: :asc, id: :asc } scope :latest, -> { order last_active_at: :desc, id: :desc } - scope :with_users, -> { preload(creator: [ :avatar_attachment, :account ], assignees: [ :avatar_attachment, :account ]) } - scope :preloaded, -> { with_users.preload(:board, :column, :tags, :steps, :closure, :not_now, :goldness, :activity_spike) } + scope :with_users, -> { preload(creator: [:avatar_attachment, :account], assignees: [:avatar_attachment, :account]) } + scope :preloaded, -> { with_users.preload(:column, :tags, :steps, :closure, :goldness, :activity_spike, :image_attachment, board: [:entropy], not_now: [ :user ]).with_rich_text_description_and_embeds } scope :indexed_by, ->(index) do case index diff --git a/app/models/filter/resources.rb b/app/models/filter/resources.rb index f7045f38e..f5988fc14 100644 --- a/app/models/filter/resources.rb +++ b/app/models/filter/resources.rb @@ -18,7 +18,7 @@ module Filter::Resources end def boards - creator.boards.where id: super.ids + @boards ||= creator.boards.where id: super.ids end def board_titles diff --git a/app/models/notification.rb b/app/models/notification.rb index 8e6010acd..416506783 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -14,6 +14,8 @@ class Notification < ApplicationRecord after_destroy_commit :broadcast_read after_create :bundle + scope :preloaded, -> { preload(:creator, :account, source: [ :board, :creator ]) } + delegate :notifiable_target, to: :source delegate :card, to: :source diff --git a/app/models/user.rb b/app/models/user.rb index 6d0bba141..4458712a5 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -15,6 +15,8 @@ class User < ApplicationRecord has_many :pins, dependent: :destroy has_many :pinned_cards, through: :pins, source: :card + scope :with_avatars, -> { preload(:account, :avatar_attachment) } + delegate :staff?, to: :identity, allow_nil: true def deactivate diff --git a/config/initializers/rack_mini_profiler.rb b/config/initializers/rack_mini_profiler.rb new file mode 100644 index 000000000..cd31e256c --- /dev/null +++ b/config/initializers/rack_mini_profiler.rb @@ -0,0 +1,7 @@ +if defined?(Rack::MiniProfiler) + Rack::MiniProfiler.config.tap do |config| + config.position = "top-right" + config.enable_hotwire_turbo_drive_support = true + config.pre_authorize_cb = -> (_env) { File.exist?(Rails.root.join("tmp/rack-mini-profiler-dev.txt")) } + end +end