Browse Source

Preload organisations to remove n+1 queries

pull/619/head
baarkerlounger 3 years ago
parent
commit
05c0e47c49
  1. 4
      app/controllers/users_controller.rb

4
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

Loading…
Cancel
Save