From ced1bbab0cd981a23d653672a01e05c8c077fdc1 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Thu, 30 Mar 2017 23:00:00 -0700 Subject: Eliminate unnecessary queries that add ~500 ms of load time for a large issue Looking at the SQL log, we see useless queries such as: ``` D, [2017-03-22T03:25:00.726710 #2629] DEBUG -- : (235.9ms) SELECT MAX("project_authorizations"."access_level") AS maximum_access_level, "project_authorizations"."user_id" AS project_authorizations_user_id FROM "project_authorizations" WHERE "project_authorizations"."project_id" = 13083 AND 1=0 GROUP BY "project_authorizations"."user_id" [["project_id", 13083]] ``` --- app/models/project_team.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'app/models/project_team.rb') diff --git a/app/models/project_team.rb b/app/models/project_team.rb index 8a53e974b6f..6d6644053f8 100644 --- a/app/models/project_team.rb +++ b/app/models/project_team.rb @@ -169,6 +169,9 @@ class ProjectTeam # Lookup only the IDs we need user_ids = user_ids - access.keys + + return access if user_ids.empty? + users_access = project.project_authorizations. where(user: user_ids). group(:user_id). -- cgit v1.2.3