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
3f27fcf3
Commit
3f27fcf3
authored
Mar 17, 2020
by
Alex Buijs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimize usage ping queries
By using batch counting
parent
5e05c233
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
13 additions
and
9 deletions
+13
-9
changelogs/unreleased/208923-enable-batch-counting-for-some-individual-queries-6.yml
...3-enable-batch-counting-for-some-individual-queries-6.yml
+5
-0
ee/app/models/packages/package.rb
ee/app/models/packages/package.rb
+1
-0
ee/app/models/users_ops_dashboard_project.rb
ee/app/models/users_ops_dashboard_project.rb
+2
-4
ee/lib/ee/gitlab/usage_data.rb
ee/lib/ee/gitlab/usage_data.rb
+3
-3
lib/gitlab/usage_data.rb
lib/gitlab/usage_data.rb
+2
-2
No files found.
changelogs/unreleased/208923-enable-batch-counting-for-some-individual-queries-6.yml
0 → 100644
View file @
3f27fcf3
---
title
:
Optimize usage ping queries by using batch counting
merge_request
:
27455
author
:
type
:
performance
ee/app/models/packages/package.rb
View file @
3f27fcf3
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
class
Packages::Package
<
ApplicationRecord
class
Packages::Package
<
ApplicationRecord
include
Sortable
include
Sortable
include
Gitlab
::
SQL
::
Pattern
include
Gitlab
::
SQL
::
Pattern
include
UsageStatistics
belongs_to
:project
belongs_to
:project
# package_files must be destroyed by ruby code in order to properly remove carrierwave uploads and update project statistics
# package_files must be destroyed by ruby code in order to properly remove carrierwave uploads and update project statistics
...
...
ee/app/models/users_ops_dashboard_project.rb
View file @
3f27fcf3
# frozen_string_literal: true
# frozen_string_literal: true
class
UsersOpsDashboardProject
<
ApplicationRecord
class
UsersOpsDashboardProject
<
ApplicationRecord
include
UsageStatistics
belongs_to
:project
belongs_to
:project
belongs_to
:user
belongs_to
:user
validates
:user
,
presence:
true
validates
:user
,
presence:
true
validates
:user_id
,
uniqueness:
{
scope:
[
:project_id
]
}
validates
:user_id
,
uniqueness:
{
scope:
[
:project_id
]
}
validates
:project
,
presence:
true
validates
:project
,
presence:
true
def
self
.
distinct_users
(
users
)
select
(
'distinct user_id'
).
joins
(
:user
).
merge
(
users
)
end
end
end
ee/lib/ee/gitlab/usage_data.rb
View file @
3f27fcf3
...
@@ -129,7 +129,7 @@ module EE
...
@@ -129,7 +129,7 @@ module EE
def
operations_dashboard_usage
def
operations_dashboard_usage
users_with_ops_dashboard_as_default
=
count
(
::
User
.
active
.
with_dashboard
(
'operations'
))
users_with_ops_dashboard_as_default
=
count
(
::
User
.
active
.
with_dashboard
(
'operations'
))
users_with_projects_added
=
count
(
UsersOpsDashboardProject
.
distinct_users
(
::
User
.
active
),
batch:
false
)
users_with_projects_added
=
distinct_count
(
UsersOpsDashboardProject
.
joins
(
:user
).
merge
(
::
User
.
active
),
:user_id
)
# rubocop:disable CodeReuse/ActiveRecord
{
{
operations_dashboard_default_dashboard:
users_with_ops_dashboard_as_default
,
operations_dashboard_default_dashboard:
users_with_ops_dashboard_as_default
,
...
@@ -154,7 +154,7 @@ module EE
...
@@ -154,7 +154,7 @@ module EE
merge_requests_with_required_codeowners:
distinct_count
(
::
ApprovalMergeRequestRule
.
code_owner_approval_required
,
:merge_request_id
),
merge_requests_with_required_codeowners:
distinct_count
(
::
ApprovalMergeRequestRule
.
code_owner_approval_required
,
:merge_request_id
),
projects_mirrored_with_pipelines_enabled:
count
(
::
Project
.
mirrored_with_enabled_pipelines
),
projects_mirrored_with_pipelines_enabled:
count
(
::
Project
.
mirrored_with_enabled_pipelines
),
projects_reporting_ci_cd_back_to_github:
count
(
::
GithubService
.
without_defaults
.
active
),
projects_reporting_ci_cd_back_to_github:
count
(
::
GithubService
.
without_defaults
.
active
),
projects_with_packages:
count
(
::
Packages
::
Package
.
select
(
'distinct project_id'
),
batch:
false
),
projects_with_packages:
distinct_count
(
::
Packages
::
Package
,
:project_id
),
projects_with_prometheus_alerts:
distinct_count
(
PrometheusAlert
,
:project_id
),
projects_with_prometheus_alerts:
distinct_count
(
PrometheusAlert
,
:project_id
),
projects_with_tracing_enabled:
count
(
ProjectTracingSetting
),
projects_with_tracing_enabled:
count
(
ProjectTracingSetting
),
template_repositories:
count
(
::
Project
.
with_repos_templates
,
batch:
false
)
+
count
(
::
Project
.
with_groups_level_repos_templates
,
batch:
false
)
template_repositories:
count
(
::
Project
.
with_repos_templates
,
batch:
false
)
+
count
(
::
Project
.
with_groups_level_repos_templates
,
batch:
false
)
...
@@ -253,7 +253,7 @@ module EE
...
@@ -253,7 +253,7 @@ module EE
clusters:
distinct_count
(
::
Clusters
::
Cluster
.
where
(
time_period
),
:user_id
),
clusters:
distinct_count
(
::
Clusters
::
Cluster
.
where
(
time_period
),
:user_id
),
clusters_applications_prometheus:
::
Clusters
::
Applications
::
Prometheus
.
where
(
time_period
).
distinct_by_user
,
clusters_applications_prometheus:
::
Clusters
::
Applications
::
Prometheus
.
where
(
time_period
).
distinct_by_user
,
operations_dashboard_default_dashboard:
count
(
::
User
.
active
.
with_dashboard
(
'operations'
).
where
(
time_period
)),
operations_dashboard_default_dashboard:
count
(
::
User
.
active
.
with_dashboard
(
'operations'
).
where
(
time_period
)),
operations_dashboard_users_with_projects_added:
count
(
UsersOpsDashboardProject
.
distinct_users
(
::
User
.
active
).
where
(
time_period
),
batch:
false
),
operations_dashboard_users_with_projects_added:
distinct_count
(
UsersOpsDashboardProject
.
joins
(
:user
).
merge
(
::
User
.
active
).
where
(
time_period
),
:user_id
),
projects_prometheus_active:
distinct_count
(
::
Project
.
with_active_prometheus_service
.
where
(
time_period
),
:creator_id
),
projects_prometheus_active:
distinct_count
(
::
Project
.
with_active_prometheus_service
.
where
(
time_period
),
:creator_id
),
projects_with_error_tracking_enabled:
distinct_count
(
::
Project
.
with_enabled_error_tracking
.
where
(
time_period
),
:creator_id
),
projects_with_error_tracking_enabled:
distinct_count
(
::
Project
.
with_enabled_error_tracking
.
where
(
time_period
),
:creator_id
),
projects_with_tracing_enabled:
distinct_count
(
::
Project
.
with_tracing_enabled
.
where
(
time_period
),
:creator_id
)
projects_with_tracing_enabled:
distinct_count
(
::
Project
.
with_tracing_enabled
.
where
(
time_period
),
:creator_id
)
...
...
lib/gitlab/usage_data.rb
View file @
3f27fcf3
...
@@ -218,9 +218,9 @@ module Gitlab
...
@@ -218,9 +218,9 @@ module Gitlab
results
[
:projects_jira_server_active
]
+=
counts
[
:server
].
count
if
counts
[
:server
]
results
[
:projects_jira_server_active
]
+=
counts
[
:server
].
count
if
counts
[
:server
]
results
[
:projects_jira_cloud_active
]
+=
counts
[
:cloud
].
count
if
counts
[
:cloud
]
results
[
:projects_jira_cloud_active
]
+=
counts
[
:cloud
].
count
if
counts
[
:cloud
]
if
results
[
:projects_jira_active
]
==
-
1
if
results
[
:projects_jira_active
]
==
-
1
results
[
:projects_jira_active
]
=
count
(
services
,
batch:
false
)
results
[
:projects_jira_active
]
=
services
.
size
else
else
results
[
:projects_jira_active
]
+=
count
(
services
,
batch:
false
)
results
[
:projects_jira_active
]
+=
services
.
size
end
end
end
end
...
...
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