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
cc1442bb
Commit
cc1442bb
authored
Nov 13, 2019
by
Kerri Miller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use cache key from diffable for Redis
parent
f6ae155f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
5 deletions
+6
-5
lib/gitlab/diff/highlight_cache.rb
lib/gitlab/diff/highlight_cache.rb
+4
-4
spec/lib/gitlab/diff/highlight_cache_spec.rb
spec/lib/gitlab/diff/highlight_cache_spec.rb
+2
-1
No files found.
lib/gitlab/diff/highlight_cache.rb
View file @
cc1442bb
...
...
@@ -11,7 +11,7 @@ module Gitlab
def
initialize
(
diff_collection
,
backend:
Rails
.
cache
)
@backend
=
backend
@diff_collection
=
diff_collection
@redis_key
=
diffable
.
cache_key
if
Feature
.
enabled?
(
:redis_diff_caching
)
@redis_key
=
"highlighted-diff-files:
#{
diffable
.
cache_key
}
"
if
Feature
.
enabled?
(
:redis_diff_caching
)
end
# - Reads from cache
...
...
@@ -62,7 +62,7 @@ module Gitlab
Redis
::
Cache
.
with
do
|
redis
|
redis
.
multi
do
|
multi
|
hash
.
each
do
|
diff_file_id
,
highlighted_diff_lines_hash
|
multi
.
hset
(
key
.
to_s
,
diff_file_id
,
highlighted_diff_lines_hash
.
to_json
)
multi
.
hset
(
@redis_key
,
diff_file_id
,
highlighted_diff_lines_hash
.
to_json
)
# HSETs have to have their expiration date manually updated
#
...
...
@@ -74,13 +74,13 @@ module Gitlab
def
read_entire_redis_hash
Redis
::
Cache
.
with
do
|
redis
|
redis
.
hgetall
(
key
.
to_s
)
redis
.
hgetall
(
@redis_key
)
end
end
def
read_single_entry_from_redis_hash
(
diff_file_id
)
Redis
::
Cache
.
with
do
|
redis
|
redis
.
hget
(
key
.
to_s
,
diff_file_id
)
redis
.
hget
(
@redis_key
,
diff_file_id
)
end
end
...
...
spec/lib/gitlab/diff/highlight_cache_spec.rb
View file @
cc1442bb
...
...
@@ -117,10 +117,11 @@ describe Gitlab::Diff::HighlightCache, :clean_gitlab_redis_cache do
describe
'#write_to_redis_hash'
do
let
(
:backend
)
{
Rails
.
cache
}
let
(
:cache_key
)
{
cache
.
diffable
.
cache_key
}
it
'creates or updates a Redis hash'
do
expect
{
cache
.
write_to_redis_hash
(
diff_hash
)
}
.
to
change
{
Gitlab
::
Redis
::
Cache
.
with
{
|
r
|
r
.
hgetall
(
cache
.
key
.
to_s
)
}
}
.
to
change
{
Gitlab
::
Redis
::
Cache
.
with
{
|
r
|
r
.
hgetall
(
cache
_key
)
}
}
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