Skip to content

Commit f32cac3

Browse files
committed
with the help of bullet, use and avoid eager loading correctly
1 parent 5caa8a2 commit f32cac3

File tree

5 files changed

+22
-5
lines changed

5 files changed

+22
-5
lines changed

Gemfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ gem "tzinfo-data", platforms: %i[mingw mswin x64_mingw jruby]
5757
# Misc gems required for the app
5858
gem "country_select", "~> 8.0.3"
5959
gem "trix-rails", require: "trix"
60+
gem "react-rails", "~> 3.2"
6061

6162
# Storing objects/images/documents
6263
gem "aws-sdk-s3", require: false
@@ -72,6 +73,7 @@ group :development, :test do
7273
end
7374

7475
group :development do
76+
gem "bullet", "~> 7.1" # Help to kill N+1 queries and unused eager loading
7577
gem "guard"
7678
gem "guard-rspec", require: false
7779
gem "web-console" # Use console on exceptions pages [https://github.com/rails/web-console]
@@ -87,12 +89,10 @@ group :test do
8789
gem "factory_bot_rails", "~> 6.2"
8890
gem "faker", "~> 3.2"
8991
gem "pundit-matchers", "~> 3.1"
92+
gem "capybara"
9093

9194
# Use system testing [https://guides.rubyonrails.org/testing.html#system-testing]
9295
# @todo check if these are required and remove if not
93-
gem "capybara"
9496
gem "selenium-webdriver"
9597
gem "webdrivers"
9698
end
97-
98-
gem "react-rails", "~> 3.2"

Gemfile.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ GEM
117117
bugsnag (6.26.3)
118118
concurrent-ruby (~> 1.0)
119119
builder (3.2.4)
120+
bullet (7.1.6)
121+
activesupport (>= 3.0.0)
122+
uniform_notifier (~> 1.11)
120123
capybara (3.40.0)
121124
addressable
122125
matrix
@@ -456,6 +459,7 @@ GEM
456459
concurrent-ruby (~> 1.0)
457460
unaccent (0.4.0)
458461
unicode-display_width (2.5.0)
462+
uniform_notifier (1.16.0)
459463
warden (1.2.9)
460464
rack (>= 2.0.9)
461465
web-console (4.2.1)
@@ -487,6 +491,7 @@ DEPENDENCIES
487491
aws-sdk-s3
488492
bootsnap
489493
bugsnag (~> 6.26)
494+
bullet (~> 7.1)
490495
capybara
491496
country_select (~> 8.0.3)
492497
cssbundling-rails (~> 1.4)

app/controllers/notifications_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ class NotificationsController < ApplicationController
33

44
after_action :mark_notifications_as_read, only: :index
55
def index
6-
@notifications = current_user.notifications.newest_first
6+
@notifications = current_user.notifications.includes(:event).newest_first
77
end
88

99
private

app/controllers/stories_controller.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,11 @@ def update_story
101101
end
102102

103103
def set_story
104-
@story = policy_scope(Story).with_attached_documents.includes(:user, story_updates: [:user]).find(params[:id])
104+
@story = policy_scope(Story).with_attached_documents.includes(preload).find(params[:id])
105+
end
106+
107+
def preload
108+
[:user, story_updates: [:user]] if action_name == "show"
105109
end
106110

107111
def permitted_attrs

config/environments/development.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
require "active_support/core_ext/integer/time"
22

33
Rails.application.configure do
4+
config.after_initialize do
5+
Bullet.enable = true
6+
Bullet.bullet_logger = true
7+
Bullet.console = true
8+
Bullet.rails_logger = true
9+
Bullet.add_footer = true
10+
end
11+
412
# Settings specified here will take precedence over those in config/application.rb.
513

614
# In the development environment your application's code is reloaded any time

0 commit comments

Comments
 (0)