From 08e372a7ca812e9c07f7abd09f44aa3bc2d40cb4 Mon Sep 17 00:00:00 2001 From: baarkerlounger Date: Thu, 19 May 2022 10:09:26 +0100 Subject: [PATCH] Preload organisations to remove n+1 queries --- app/controllers/users_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index b4854da47..f3ba40f1d 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -9,13 +9,13 @@ class UsersController < ApplicationController def index redirect_to users_organisation_path(current_user.organisation) unless current_user.support? - @pagy, @users = pagy(User.all.where(active: true)) + @pagy, @users = pagy(User.all.where(active: true).includes(:organisation)) respond_to do |format| format.html format.csv do if current_user.support? - send_data User.all.where(active: true).to_csv, filename: "users-#{Time.zone.now}.csv" + send_data User.all.where(active: true).includes(:organisation).to_csv, filename: "users-#{Time.zone.now}.csv" else head :unauthorized end