From c88f8dcdaab4cc059c1cd9d9c14f148f7fadc771 Mon Sep 17 00:00:00 2001 From: VISHAL DEEPAK Date: Thu, 9 Sep 2021 15:41:03 +0530 Subject: [PATCH] In dashboard show api eager load collection with articles (#14677) * In dashboard show api eager load collection with articles * Dashboard Article Row view now loads collection to suppress bullet warning of eager loading --- app/controllers/dashboards_controller.rb | 2 +- config/environments/development.rb | 1 + config/environments/test.rb | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/dashboards_controller.rb b/app/controllers/dashboards_controller.rb index eb4578886..676091a18 100644 --- a/app/controllers/dashboards_controller.rb +++ b/app/controllers/dashboards_controller.rb @@ -23,7 +23,7 @@ class DashboardsController < ApplicationController @reactions_count = @articles.sum(&:public_reactions_count) @page_views_count = @articles.sum(&:page_views_count) - @articles = @articles.sorting(params[:sort]).decorate + @articles = @articles.includes(:collection).sorting(params[:sort]).decorate @articles = Kaminari.paginate_array(@articles).page(params[:page]).per(50) end diff --git a/config/environments/development.rb b/config/environments/development.rb index 2c75b9349..ad791414c 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -128,6 +128,7 @@ Rails.application.configure do Bullet.add_safelist(type: :n_plus_one_query, class_name: "ActsAsTaggableOn::Tagging", association: :tag) # Supress incorrect warnings from Bullet due to included columns: https://github.com/flyerhzm/bullet/issues/147 Bullet.add_safelist(type: :unused_eager_loading, class_name: "Article", association: :top_comments) + Bullet.add_safelist(type: :unused_eager_loading, class_name: "Article", association: :collection) Bullet.add_safelist(type: :unused_eager_loading, class_name: "Comment", association: :user) # NOTE: @citizen428 Temporarily ignoring this while working out user - profile relationship Bullet.add_safelist(type: :n_plus_one_query, class_name: "User", association: :profile) diff --git a/config/environments/test.rb b/config/environments/test.rb index cbcd1f520..4e66cca7a 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -79,6 +79,7 @@ Rails.application.configure do Bullet.add_safelist(type: :n_plus_one_query, class_name: "ActsAsTaggableOn::Tagging", association: :tag) # Supress incorrect warnings from Bullet due to included columns: https://github.com/flyerhzm/bullet/issues/147 Bullet.add_safelist(type: :unused_eager_loading, class_name: "Article", association: :top_comments) + Bullet.add_safelist(type: :unused_eager_loading, class_name: "Article", association: :collection) Bullet.add_safelist(type: :unused_eager_loading, class_name: "Comment", association: :user) # @citizen428: We have not yet resolved all user - profile preloads related to profilge generalization Bullet.add_safelist(type: :n_plus_one_query, class_name: "User", association: :profile)