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
e9629b82
Commit
e9629b82
authored
Mar 13, 2020
by
Alina Mihaila
Committed by
Mayra Cabrera
Mar 13, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move approximate counters to batch counting
parent
0db58ea8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
9 additions
and
36 deletions
+9
-36
changelogs/unreleased/210332-approximate-counters-are-not-working-on-gitlab-com.yml
...32-approximate-counters-are-not-working-on-gitlab-com.yml
+5
-0
lib/gitlab/usage_data.rb
lib/gitlab/usage_data.rb
+4
-13
spec/lib/gitlab/usage_data_spec.rb
spec/lib/gitlab/usage_data_spec.rb
+0
-23
No files found.
changelogs/unreleased/210332-approximate-counters-are-not-working-on-gitlab-com.yml
0 → 100644
View file @
e9629b82
---
title
:
Use batch counters instead of approximate counters in usage data
merge_request
:
27218
author
:
type
:
performance
lib/gitlab/usage_data.rb
View file @
e9629b82
...
...
@@ -2,7 +2,6 @@
module
Gitlab
class
UsageData
APPROXIMATE_COUNT_MODELS
=
[
Label
,
MergeRequest
,
Note
,
Todo
].
freeze
BATCH_SIZE
=
100
class
<<
self
...
...
@@ -107,10 +106,12 @@ module Gitlab
suggestions:
count
(
Suggestion
),
todos:
count
(
Todo
),
uploads:
count
(
Upload
),
web_hooks:
count
(
WebHook
)
web_hooks:
count
(
WebHook
),
labels:
count
(
Label
),
merge_requests:
count
(
MergeRequest
),
notes:
count
(
Note
)
}.
merge
(
services_usage
,
approximate_counts
,
usage_counters
,
user_preferences_usage
,
ingress_modsecurity_usage
...
...
@@ -251,16 +252,6 @@ module Gitlab
fallback
end
def
approximate_counts
approx_counts
=
Gitlab
::
Database
::
Count
.
approximate_counts
(
APPROXIMATE_COUNT_MODELS
)
APPROXIMATE_COUNT_MODELS
.
each_with_object
({})
do
|
model
,
result
|
key
=
model
.
name
.
underscore
.
pluralize
.
to_sym
result
[
key
]
=
approx_counts
[
model
]
||
-
1
end
end
def
installation_type
if
Rails
.
env
.
production?
Gitlab
::
INSTALLATION_TYPE
...
...
spec/lib/gitlab/usage_data_spec.rb
View file @
e9629b82
...
...
@@ -387,29 +387,6 @@ describe Gitlab::UsageData do
expect
(
described_class
.
count
(
relation
,
fallback:
15
,
batch:
false
)).
to
eq
(
15
)
end
end
describe
'#approximate_counts'
do
it
'gets approximate counts for selected models'
,
:aggregate_failures
do
create
(
:label
)
expect
(
Gitlab
::
Database
::
Count
).
to
receive
(
:approximate_counts
)
.
with
(
described_class
::
APPROXIMATE_COUNT_MODELS
).
once
.
and_call_original
counts
=
described_class
.
approximate_counts
.
values
expect
(
counts
.
count
).
to
eq
(
described_class
::
APPROXIMATE_COUNT_MODELS
.
count
)
expect
(
counts
.
any?
{
|
count
|
count
<
0
}).
to
be_falsey
end
it
'returns default values if counts can not be retrieved'
,
:aggregate_failures
do
described_class
::
APPROXIMATE_COUNT_MODELS
.
map
do
|
model
|
model
.
name
.
underscore
.
pluralize
.
to_sym
end
expect
(
Gitlab
::
Database
::
Count
).
to
receive
(
:approximate_counts
).
and_return
({})
expect
(
described_class
.
approximate_counts
.
values
.
uniq
).
to
eq
([
-
1
])
end
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