Skip to content

Commit

Permalink
with the help of bullet, use and avoid eager loading correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
madhums committed Mar 6, 2024
1 parent 5caa8a2 commit f32cac3
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
6 changes: 3 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ gem "tzinfo-data", platforms: %i[mingw mswin x64_mingw jruby]
# Misc gems required for the app
gem "country_select", "~> 8.0.3"
gem "trix-rails", require: "trix"
gem "react-rails", "~> 3.2"

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

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

# Use system testing [https://guides.rubyonrails.org/testing.html#system-testing]
# @todo check if these are required and remove if not
gem "capybara"
gem "selenium-webdriver"
gem "webdrivers"
end

gem "react-rails", "~> 3.2"
5 changes: 5 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ GEM
bugsnag (6.26.3)
concurrent-ruby (~> 1.0)
builder (3.2.4)
bullet (7.1.6)
activesupport (>= 3.0.0)
uniform_notifier (~> 1.11)
capybara (3.40.0)
addressable
matrix
Expand Down Expand Up @@ -456,6 +459,7 @@ GEM
concurrent-ruby (~> 1.0)
unaccent (0.4.0)
unicode-display_width (2.5.0)
uniform_notifier (1.16.0)
warden (1.2.9)
rack (>= 2.0.9)
web-console (4.2.1)
Expand Down Expand Up @@ -487,6 +491,7 @@ DEPENDENCIES
aws-sdk-s3
bootsnap
bugsnag (~> 6.26)
bullet (~> 7.1)
capybara
country_select (~> 8.0.3)
cssbundling-rails (~> 1.4)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/notifications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class NotificationsController < ApplicationController

after_action :mark_notifications_as_read, only: :index
def index
@notifications = current_user.notifications.newest_first
@notifications = current_user.notifications.includes(:event).newest_first
end

private
Expand Down
6 changes: 5 additions & 1 deletion app/controllers/stories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,11 @@ def update_story
end

def set_story
@story = policy_scope(Story).with_attached_documents.includes(:user, story_updates: [:user]).find(params[:id])
@story = policy_scope(Story).with_attached_documents.includes(preload).find(params[:id])
end

def preload
[:user, story_updates: [:user]] if action_name == "show"
end

def permitted_attrs
Expand Down
8 changes: 8 additions & 0 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
require "active_support/core_ext/integer/time"

Rails.application.configure do
config.after_initialize do
Bullet.enable = true
Bullet.bullet_logger = true
Bullet.console = true
Bullet.rails_logger = true
Bullet.add_footer = true
end

# Settings specified here will take precedence over those in config/application.rb.

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

0 comments on commit f32cac3

Please sign in to comment.