Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
cb8e67c2
Commit
cb8e67c2
authored
Oct 02, 2017
by
Bob Van Landuyt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve count queries and move them to contants
parent
af0b8e05
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
27 deletions
+28
-27
app/finders/group_descendants_finder.rb
app/finders/group_descendants_finder.rb
+28
-27
No files found.
app/finders/group_descendants_finder.rb
View file @
cb8e67c2
...
@@ -3,6 +3,30 @@ class GroupDescendantsFinder
...
@@ -3,6 +3,30 @@ class GroupDescendantsFinder
attr_reader
:current_user
,
:parent_group
,
:params
attr_reader
:current_user
,
:parent_group
,
:params
PROJECT_COUNT_SQL
=
<<~
PROJECTCOUNT
.
freeze
(SELECT COUNT(*) AS preloaded_project_count
FROM projects
WHERE projects.namespace_id = namespaces.id
AND projects.archived IS NOT true)
PROJECTCOUNT
SUBGROUP_COUNT_SQL
=
<<~
SUBGROUPCOUNT
.
freeze
(SELECT COUNT(*) AS preloaded_subgroup_count
FROM namespaces children
WHERE children.parent_id = namespaces.id)
SUBGROUPCOUNT
MEMBER_COUNT_SQL
=
<<~
MEMBERCOUNT
.
freeze
(SELECT COUNT(*) AS preloaded_member_count
FROM members
WHERE members.source_type = 'Namespace'
AND members.source_id = namespaces.id
AND members.requested_at IS NULL)
MEMBERCOUNT
GROUP_SELECTS
=
[
'namespaces.*'
,
PROJECT_COUNT_SQL
,
SUBGROUP_COUNT_SQL
,
MEMBER_COUNT_SQL
].
freeze
def
initialize
(
current_user:
nil
,
parent_group
:,
params:
{})
def
initialize
(
current_user:
nil
,
parent_group
:,
params:
{})
@current_user
=
current_user
@current_user
=
current_user
@parent_group
=
parent_group
@parent_group
=
parent_group
...
@@ -31,39 +55,16 @@ class GroupDescendantsFinder
...
@@ -31,39 +55,16 @@ class GroupDescendantsFinder
def
children
def
children
return
@children
if
@children
return
@children
if
@children
projects_count
=
<<~
PROJECTCOUNT
subgroups_with_counts
=
subgroups
.
with_route
(SELECT COUNT(projects.id) AS preloaded_project_count
.
page
(
params
[
:page
]).
per
(
per_page
)
FROM projects WHERE projects.namespace_id = namespaces.id)
.
select
(
GROUP_SELECTS
)
PROJECTCOUNT
subgroup_count
=
<<~
SUBGROUPCOUNT
(SELECT COUNT(children.id) AS preloaded_subgroup_count
FROM namespaces children
WHERE children.parent_id = namespaces.id)
SUBGROUPCOUNT
member_count
=
<<~
MEMBERCOUNT
(SELECT COUNT(members.user_id) AS preloaded_member_count
FROM members
WHERE members.source_type = 'Namespace'
AND members.source_id = namespaces.id
AND members.requested_at IS NULL)
MEMBERCOUNT
group_selects
=
[
'namespaces.*'
,
projects_count
,
subgroup_count
,
member_count
]
subgroups_with_counts
=
subgroups
.
with_route
.
page
(
params
[
:page
]).
per
(
per_page
).
select
(
group_selects
)
group_page_count
=
subgroups_with_counts
.
total_pages
subgroup_page
=
subgroups_with_counts
.
current_page
paginated_projects
=
projects
.
with_route
.
page
(
subgroup_page
-
group_page_count
)
paginated_projects
=
projects
.
with_route
.
page
(
subgroup_page
-
group_page_count
)
.
per
(
per_page
-
subgroups_with_counts
.
size
)
.
per
(
per_page
-
subgroups_with_counts
.
size
)
if
params
[
:filter
]
if
params
[
:filter
]
ancestors_for_project_search
=
ancestors_for_groups
(
Group
.
where
(
id:
paginated_projects
.
select
(
:namespace_id
)))
ancestors_for_project_search
=
ancestors_for_groups
(
Group
.
where
(
id:
paginated_projects
.
select
(
:namespace_id
)))
subgroups_with_counts
=
ancestors_for_project_search
.
with_route
.
select
(
group_selects
)
|
subgroups_with_counts
subgroups_with_counts
=
ancestors_for_project_search
.
with_route
.
select
(
GROUP_SELECTS
)
|
subgroups_with_counts
end
end
@children
=
subgroups_with_counts
+
paginated_projects
@children
=
subgroups_with_counts
+
paginated_projects
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment