From f32cac3936b14bdbc00eab8c64c01979c4dc0ea2 Mon Sep 17 00:00:00 2001 From: madhums Date: Wed, 6 Mar 2024 20:02:33 +0100 Subject: [PATCH] with the help of bullet, use and avoid eager loading correctly --- Gemfile | 6 +++--- Gemfile.lock | 5 +++++ app/controllers/notifications_controller.rb | 2 +- app/controllers/stories_controller.rb | 6 +++++- config/environments/development.rb | 8 ++++++++ 5 files changed, 22 insertions(+), 5 deletions(-) diff --git a/Gemfile b/Gemfile index cf22b65..f101e7b 100644 --- a/Gemfile +++ b/Gemfile @@ -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 @@ -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] @@ -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" diff --git a/Gemfile.lock b/Gemfile.lock index f92dccd..fae1323 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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 @@ -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) @@ -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) diff --git a/app/controllers/notifications_controller.rb b/app/controllers/notifications_controller.rb index c0f2b78..9bd87e8 100644 --- a/app/controllers/notifications_controller.rb +++ b/app/controllers/notifications_controller.rb @@ -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 diff --git a/app/controllers/stories_controller.rb b/app/controllers/stories_controller.rb index 31f7172..2c393df 100644 --- a/app/controllers/stories_controller.rb +++ b/app/controllers/stories_controller.rb @@ -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 diff --git a/config/environments/development.rb b/config/environments/development.rb index 10c9bc3..36e2ea0 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -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