summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2017-03-30 23:00:00 -0700
committerStan Hu <stanhu@gmail.com>2017-03-30 23:00:00 -0700
commitced1bbab0cd981a23d653672a01e05c8c077fdc1 (patch)
treeac3a479b5556c0978b83b02f1e99da07feaf2e48
parentbcb0a554dd4f8754ab1d6a876edc1481e04aa711 (diff)
downloadgitlab-ce-ced1bbab0cd981a23d653672a01e05c8c077fdc1.tar.gz
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]] ```
-rw-r--r--app/models/project_team.rb3
1 files changed, 3 insertions, 0 deletions
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).