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
8e88429c
Commit
8e88429c
authored
Mar 11, 2020
by
Kerri Miller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Begin observing size of cached highlighted diffs
parent
93f07c47
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
0 deletions
+41
-0
lib/gitlab/diff/highlight_cache.rb
lib/gitlab/diff/highlight_cache.rb
+19
-0
spec/lib/gitlab/diff/highlight_cache_spec.rb
spec/lib/gitlab/diff/highlight_cache_spec.rb
+22
-0
No files found.
lib/gitlab/diff/highlight_cache.rb
View file @
8e88429c
...
@@ -101,6 +101,8 @@ module Gitlab
...
@@ -101,6 +101,8 @@ module Gitlab
#
#
redis
.
expire
(
key
,
EXPIRATION
)
redis
.
expire
(
key
,
EXPIRATION
)
end
end
record_memory_usage
(
fetch_memory_usage
(
redis
,
key
))
end
end
# Subsequent read_file calls would need the latest cache.
# Subsequent read_file calls would need the latest cache.
...
@@ -109,6 +111,23 @@ module Gitlab
...
@@ -109,6 +111,23 @@ module Gitlab
clear_memoization
(
:cacheable_files
)
clear_memoization
(
:cacheable_files
)
end
end
def
record_memory_usage
(
memory_usage
)
if
memory_usage
self
.
class
.
gitlab_redis_diff_caching_memory_usage_bytes
.
observe
({},
memory_usage
)
end
end
def
fetch_memory_usage
(
redis
,
key
)
# Redis versions prior to 4.0.0 do not support memory usage reporting
# for a specific key. As of 11-March-2020 we support Redis 3.x, so
# need to account for this. We can remove this check once we
# officially cease supporting versions <4.0.0.
#
return
if
Gem
::
Version
.
new
(
redis
.
info
[
"redis_version"
])
<
Gem
::
Version
.
new
(
"4"
)
redis
.
memory
(
"USAGE"
,
key
)
end
def
file_paths
def
file_paths
strong_memoize
(
:file_paths
)
do
strong_memoize
(
:file_paths
)
do
diff_files
.
collect
(
&
:file_path
)
diff_files
.
collect
(
&
:file_path
)
...
...
spec/lib/gitlab/diff/highlight_cache_spec.rb
View file @
8e88429c
...
@@ -97,6 +97,28 @@ describe Gitlab::Diff::HighlightCache, :clean_gitlab_redis_cache do
...
@@ -97,6 +97,28 @@ describe Gitlab::Diff::HighlightCache, :clean_gitlab_redis_cache do
let
(
:paths
)
{
merge_request
.
diffs
.
raw_diff_files
.
select
(
&
:text?
).
map
(
&
:file_path
)
}
let
(
:paths
)
{
merge_request
.
diffs
.
raw_diff_files
.
select
(
&
:text?
).
map
(
&
:file_path
)
}
end
end
it
'updates memory usage metrics if Redis version >= 4'
do
allow_next_instance_of
(
Redis
)
do
|
redis
|
allow
(
redis
).
to
receive
(
:info
).
and_return
({
"redis_version"
=>
"4.0.0"
})
expect
(
described_class
.
gitlab_redis_diff_caching_memory_usage_bytes
)
.
to
receive
(
:observe
).
and_call_original
cache
.
send
(
:write_to_redis_hash
,
diff_hash
)
end
end
it
'does not update memory usage metrics if Redis version < 4'
do
allow_next_instance_of
(
Redis
)
do
|
redis
|
allow
(
redis
).
to
receive
(
:info
).
and_return
({
"redis_version"
=>
"3.0.0"
})
expect
(
described_class
.
gitlab_redis_diff_caching_memory_usage_bytes
)
.
not_to
receive
(
:observe
).
and_call_original
cache
.
send
(
:write_to_redis_hash
,
diff_hash
)
end
end
context
'different diff_collections for the same diffable'
do
context
'different diff_collections for the same diffable'
do
before
do
before
do
cache
.
write_if_empty
cache
.
write_if_empty
...
...
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