summaryrefslogtreecommitdiff
path: root/app/serializers
diff options
context:
space:
mode:
authorBob Van Landuyt <bob@vanlanduyt.co>2017-09-26 11:22:52 +0200
committerBob Van Landuyt <bob@vanlanduyt.co>2017-10-04 22:49:42 +0200
commitac0b104ae4968adaed7b94db76c0ac86badb6d6b (patch)
treebe0737e1d9971911bedc48bb05d1fe84e46ac93a /app/serializers
parentcd85c22faa7092edabf252fa157125ea571ed054 (diff)
downloadgitlab-ce-ac0b104ae4968adaed7b94db76c0ac86badb6d6b.tar.gz
Minimize the number of queries by preloading counts and ancestors
By preloading the count of members, projects and subgroups of a group, we don't need to query them later. We also preload the entire hierarchy for a search result and include the counts so we don't need to query for them again
Diffstat (limited to 'app/serializers')
-rw-r--r--app/serializers/group_child_entity.rb21
1 files changed, 17 insertions, 4 deletions
diff --git a/app/serializers/group_child_entity.rb b/app/serializers/group_child_entity.rb
index 8a2624c3d32..91e26272355 100644
--- a/app/serializers/group_child_entity.rb
+++ b/app/serializers/group_child_entity.rb
@@ -60,15 +60,23 @@ class GroupChildEntity < Grape::Entity
end
def children_count
- @children_count ||= children_finder.total_count
+ @children_count ||= project_count + subgroup_count
end
def project_count
- @project_count ||= children_finder.project_count
+ @project_count ||= if object.respond_to?(:preloaded_project_count)
+ object.preloaded_project_count
+ else
+ children_finder.project_count
+ end
end
def subgroup_count
- @subgroup_count ||= children_finder.subgroup_count
+ @subgroup_count ||= if object.respond_to?(:preloaded_subgroup_count)
+ object.preloaded_subgroup_count
+ else
+ children_finder.subgroup_count
+ end
end
def leave_path
@@ -88,6 +96,11 @@ class GroupChildEntity < Grape::Entity
end
def number_users_with_delimiter
- number_with_delimiter(object.users.count)
+ member_count = if object.respond_to?(:preloaded_member_count)
+ object.preloaded_member_count
+ else
+ object.users.count
+ end
+ number_with_delimiter(member_count)
end
end