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
88d1f113
Commit
88d1f113
authored
Jul 02, 2021
by
Piotr Skorupa
Committed by
charlie ablett
Jul 06, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use Gitlab::Cache.fetch_once for min/max caching
parent
cc276954
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
4 deletions
+11
-4
lib/gitlab/usage/metrics/instrumentations/database_metric.rb
lib/gitlab/usage/metrics/instrumentations/database_metric.rb
+2
-2
spec/lib/gitlab/usage/metrics/instrumentations/database_metric_spec.rb
...ab/usage/metrics/instrumentations/database_metric_spec.rb
+9
-2
No files found.
lib/gitlab/usage/metrics/instrumentations/database_metric.rb
View file @
88d1f113
...
...
@@ -91,11 +91,11 @@ module Gitlab
key_name
=
"metric_instrumentation/
#{
self
.
class
.
cache_key
}
"
start
=
Rails
.
cache
.
fetch
(
"
#{
key_name
}
_minimum_id"
,
expires_in:
1
.
day
)
do
start
=
Gitlab
::
Cache
.
fetch_once
(
"
#{
key_name
}
_minimum_id"
,
expires_in:
1
.
day
)
do
self
.
class
.
start
end
finish
=
Rails
.
cache
.
fetch
(
"
#{
key_name
}
_maximum_id"
,
expires_in:
1
.
day
)
do
finish
=
Gitlab
::
Cache
.
fetch_once
(
"
#{
key_name
}
_maximum_id"
,
expires_in:
1
.
day
)
do
self
.
class
.
finish
end
...
...
spec/lib/gitlab/usage/metrics/instrumentations/database_metric_spec.rb
View file @
88d1f113
...
...
@@ -26,7 +26,10 @@ RSpec.describe Gitlab::Usage::Metrics::Instrumentations::DatabaseMetric do
expect
(
subject
.
value
).
to
eq
(
3
)
end
it
'does not cache the result of start and finish'
,
:use_clean_rails_redis_caching
do
it
'does not cache the result of start and finish'
,
:request_store
,
:use_clean_rails_redis_caching
do
expect
(
Gitlab
::
Cache
).
not_to
receive
(
:fetch_once
)
expect
(
subject
).
to
receive
(
:count
).
with
(
any_args
,
hash_including
(
start:
issues
.
min_by
(
&
:id
).
id
,
finish:
issues
.
max_by
(
&
:id
).
id
)).
and_call_original
subject
.
value
expect
(
Rails
.
cache
.
read
(
'metric_instrumentation/special_issue_count_minimum_id'
)).
to
eq
(
nil
)
...
...
@@ -57,7 +60,11 @@ RSpec.describe Gitlab::Usage::Metrics::Instrumentations::DatabaseMetric do
end
.
new
(
time_frame:
'all'
)
end
it
'caches using the key name passed'
,
:use_clean_rails_redis_caching
do
it
'caches using the key name passed'
,
:request_store
,
:use_clean_rails_redis_caching
do
expect
(
Gitlab
::
Cache
).
to
receive
(
:fetch_once
).
with
(
'metric_instrumentation/special_issue_count_minimum_id'
,
any_args
).
and_call_original
expect
(
Gitlab
::
Cache
).
to
receive
(
:fetch_once
).
with
(
'metric_instrumentation/special_issue_count_maximum_id'
,
any_args
).
and_call_original
expect
(
subject
).
to
receive
(
:count
).
with
(
any_args
,
hash_including
(
start:
issues
.
min_by
(
&
:id
).
id
,
finish:
issues
.
max_by
(
&
:id
).
id
)).
and_call_original
subject
.
value
expect
(
Rails
.
cache
.
read
(
'metric_instrumentation/special_issue_count_minimum_id'
)).
to
eq
(
issues
.
min_by
(
&
:id
).
id
)
...
...
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