Skip to content

Commit

Permalink
Fix N+1.
Browse files Browse the repository at this point in the history
  • Loading branch information
yamat47 committed Aug 15, 2024
1 parent 258d71f commit ac41b3f
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions app/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Metrics/AbcSize:
Metrics/BlockLength:
Exclude:
- 'spec/**/*_spec.rb'
- 'config/environments/development.rb'

Metrics/MethodLength:
Exclude:
Expand Down
1 change: 1 addition & 0 deletions app/app/controllers/admin/game_schedules_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class GameSchedulesController < ApplicationController
def index
@game_schedules = GameSchedule.start_at_ordered
.search_by_keyword(index_params[:search])
.preload(:season, :tournament, :home_team, :visitor_team, :game_field)
.page(index_params[:page])
.per(INDEX_PER_PAGE)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Admin
class MediaPageSettingsController < ApplicationController
def show
@media_hero_images = MediaHeroImage.sort_order_ordered
@media_hero_images = MediaHeroImage.preload(image_attachment: :blob).sort_order_ordered
end
end
end
2 changes: 1 addition & 1 deletion app/app/controllers/media/game_schedules_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def index
game_schedules = GameSchedule.start_at_ordered
.game_field_ordered
.where(season: @season)
.preload(:home_team, :visitor_team, :game_field, :tournament)
.preload(:home_team, :visitor_team, :game_field, :tournament, :game_result)

# group by date.
@game_schedule_groups = game_schedules.group_by { |game_schedule| game_schedule.start_at.to_date }
Expand Down
2 changes: 2 additions & 0 deletions app/app/controllers/media/homes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ class HomesController < ApplicationController

def show
@media_hero_images = MediaHeroImage.sort_order_ordered
.preload(image_attachment: :blob)

@notices = Notice.only_published
.published_at_ordered
.limit(NOTICES_LIMIT)

@game_schedules = GameSchedule.next_scheduled_games
.preload(:game_field, :tournament, :home_team, :visitor_team, :game_result)
end
end
end
4 changes: 2 additions & 2 deletions app/app/views/admin/game_schedules/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
= GameSchedule.human_attribute_name(:home_team)
.admin-field__value
= form.select_with_image(:home_team_id,
Team.all,
Team.preload({ logo_attachment: :blob }),
value_method: :id,
text_method: :name,
image_method: :logo_url,
Expand All @@ -43,7 +43,7 @@
= GameSchedule.human_attribute_name(:visitor_team)
.admin-field__value
= form.select_with_image(:visitor_team_id,
Team.all,
Team.preload({ logo_attachment: :blob }),
value_method: :id,
text_method: :name,
image_method: :logo_url,
Expand Down
3 changes: 3 additions & 0 deletions app/config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,8 @@
Bullet.rails_logger = true
Bullet.add_footer = true
Bullet.skip_html_injection = false

Bullet.add_safelist type: :unused_eager_loading, class_name: 'ActiveStorage::Attachment',
association: :blob
end
end

0 comments on commit ac41b3f

Please sign in to comment.