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
83958cfc
Commit
83958cfc
authored
Sep 18, 2019
by
Nick Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "Don't use the redis set cache yet"
This reverts commit
034f0340
.
parent
653904bc
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
15 deletions
+50
-15
app/models/repository.rb
app/models/repository.rb
+4
-4
changelogs/unreleased/64251-branch-name-set-cache.yml
changelogs/unreleased/64251-branch-name-set-cache.yml
+5
-0
spec/models/repository_spec.rb
spec/models/repository_spec.rb
+41
-11
No files found.
app/models/repository.rb
View file @
83958cfc
...
...
@@ -249,13 +249,13 @@ class Repository
def
branch_exists?
(
branch_name
)
return
false
unless
raw_repository
branch_names
.
include?
(
branch_name
)
branch_names
_
include?
(
branch_name
)
end
def
tag_exists?
(
tag_name
)
return
false
unless
raw_repository
tag_names
.
include?
(
tag_name
)
tag_names
_
include?
(
tag_name
)
end
def
ref_exists?
(
ref
)
...
...
@@ -559,10 +559,10 @@ class Repository
end
delegate
:branch_names
,
to: :raw_repository
cache_method
:branch_names
,
fallback:
[]
cache_method
_as_redis_set
:branch_names
,
fallback:
[]
delegate
:tag_names
,
to: :raw_repository
cache_method
:tag_names
,
fallback:
[]
cache_method
_as_redis_set
:tag_names
,
fallback:
[]
delegate
:branch_count
,
:tag_count
,
:has_visible_content?
,
to: :raw_repository
cache_method
:branch_count
,
fallback:
0
...
...
changelogs/unreleased/64251-branch-name-set-cache.yml
0 → 100644
View file @
83958cfc
---
title
:
Cache branch and tag names as Redis sets
merge_request
:
30476
author
:
type
:
performance
spec/models/repository_spec.rb
View file @
83958cfc
...
...
@@ -1223,36 +1223,66 @@ describe Repository do
end
describe
'#branch_exists?'
do
it
'uses branch_names'
do
allow
(
repository
).
to
receive
(
:branch_names
).
and_return
([
'foobar'
])
let
(
:branch
)
{
repository
.
root_ref
}
expect
(
repository
.
branch_exists?
(
'foobar'
)).
to
eq
(
true
)
expect
(
repository
.
branch_exists?
(
'master'
)).
to
eq
(
false
)
subject
{
repository
.
branch_exists?
(
branch
)
}
it
'delegates to branch_names when the cache is empty'
do
repository
.
expire_branches_cache
expect
(
repository
).
to
receive
(
:branch_names
).
and_call_original
is_expected
.
to
eq
(
true
)
end
it
'uses redis set caching when the cache is filled'
do
repository
.
branch_names
# ensure the branch name cache is filled
expect
(
repository
)
.
to
receive
(
:branch_names_include?
)
.
with
(
branch
)
.
and_call_original
is_expected
.
to
eq
(
true
)
end
end
describe
'#tag_exists?'
do
it
'uses tag_names'
do
allow
(
repository
).
to
receive
(
:tag_names
).
and_return
([
'foobar'
])
let
(
:tag
)
{
repository
.
tags
.
first
.
name
}
subject
{
repository
.
tag_exists?
(
tag
)
}
it
'delegates to tag_names when the cache is empty'
do
repository
.
expire_tags_cache
expect
(
repository
).
to
receive
(
:tag_names
).
and_call_original
is_expected
.
to
eq
(
true
)
end
it
'uses redis set caching when the cache is filled'
do
repository
.
tag_names
# ensure the tag name cache is filled
expect
(
repository
)
.
to
receive
(
:tag_names_include?
)
.
with
(
tag
)
.
and_call_original
expect
(
repository
.
tag_exists?
(
'foobar'
)).
to
eq
(
true
)
expect
(
repository
.
tag_exists?
(
'master'
)).
to
eq
(
false
)
is_expected
.
to
eq
(
true
)
end
end
describe
'#branch_names'
,
:
use_clean_rails_memory_store_caching
do
describe
'#branch_names'
,
:
clean_gitlab_redis_cache
do
let
(
:fake_branch_names
)
{
[
'foobar'
]
}
it
'gets cached across Repository instances'
do
allow
(
repository
.
raw_repository
).
to
receive
(
:branch_names
).
once
.
and_return
(
fake_branch_names
)
expect
(
repository
.
branch_names
).
to
eq
(
fake_branch_names
)
expect
(
repository
.
branch_names
).
to
match_array
(
fake_branch_names
)
fresh_repository
=
Project
.
find
(
project
.
id
).
repository
expect
(
fresh_repository
.
object_id
).
not_to
eq
(
repository
.
object_id
)
expect
(
fresh_repository
.
raw_repository
).
not_to
receive
(
:branch_names
)
expect
(
fresh_repository
.
branch_names
).
to
eq
(
fake_branch_names
)
expect
(
fresh_repository
.
branch_names
).
to
match_array
(
fake_branch_names
)
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