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
4cd6c91d
Commit
4cd6c91d
authored
Sep 10, 2019
by
Nick Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Redis set cache docs and minor cleanup
parent
07323f44
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
7 deletions
+19
-7
lib/gitlab/repository_cache_adapter.rb
lib/gitlab/repository_cache_adapter.rb
+17
-5
lib/gitlab/repository_set_cache.rb
lib/gitlab/repository_set_cache.rb
+2
-2
No files found.
lib/gitlab/repository_cache_adapter.rb
View file @
4cd6c91d
...
...
@@ -35,6 +35,11 @@ module Gitlab
# name - The name of the method to be cached.
# fallback - A value to fall back to if the repository does not exist, or
# in case of a Git error. Defaults to nil.
#
# It is not safe to use this method prior to the release of 12.3, since
# 12.2 does not correctly invalidate the redis set cache value. A mixed
# code environment containing both 12.2 and 12.3 nodes breaks, while a
# mixed code environment containing both 12.3 and 12.4 nodes will work.
def
cache_method_as_redis_set
(
name
,
fallback:
nil
)
uncached_name
=
alias_uncached_method
(
name
)
...
...
@@ -44,13 +49,20 @@ module Gitlab
end
end
# Attempt to determine whether a value is in the set of values being
# cached, by performing a redis SISMEMBERS query if appropriate.
#
# If the full list is already in-memory, we're better using it directly.
#
# If the cache is not yet populated, querying it directly will give the
# wrong answer. We handle that by querying the full list - which fills
# the cache - and using it directly to answer the question.
define_method
(
"
#{
name
}
_include?"
)
do
|
value
|
# If the cache isn't populated, we can't rely on it
return
redis_set_cache
.
include?
(
name
,
value
)
if
redis_set_cache
.
exist?
(
name
)
if
strong_memoized?
(
name
)
||
!
redis_set_cache
.
exist?
(
name
)
return
__send__
(
name
).
include?
(
value
)
# rubocop:disable GitlabSecurity/PublicSend
end
# Since we have to pull all branch names to populate the cache, use
# the data we already have to answer the query just this once
__send__
(
name
).
include?
(
value
)
# rubocop:disable GitlabSecurity/PublicSend
redis_set_cache
.
include?
(
name
,
value
)
end
end
...
...
lib/gitlab/repository_set_cache.rb
View file @
4cd6c91d
...
...
@@ -13,7 +13,7 @@ module Gitlab
end
def
cache_key
(
type
)
[
type
,
namespace
,
'set'
].
join
(
':'
)
"
#{
type
}
:
#{
namespace
}
:set"
end
def
expire
(
key
)
...
...
@@ -37,7 +37,7 @@ module Gitlab
# Splitting into groups of 1000 prevents us from creating a too-long
# Redis command
value
.
in_groups_of
(
1000
,
false
)
{
|
subset
|
redis
.
sadd
(
full_key
,
subset
)
}
value
.
each_slice
(
1000
)
{
|
subset
|
redis
.
sadd
(
full_key
,
subset
)
}
redis
.
expire
(
full_key
,
expires_in
)
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