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
d383f618
Commit
d383f618
authored
Jan 08, 2019
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab-ce master
parents
826fdeaa
a0aca3ac
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
15 additions
and
41 deletions
+15
-41
app/models/repository.rb
app/models/repository.rb
+2
-10
lib/gitlab/repository_cache.rb
lib/gitlab/repository_cache.rb
+2
-2
spec/lib/gitlab/repository_cache_spec.rb
spec/lib/gitlab/repository_cache_spec.rb
+11
-11
spec/models/repository_spec.rb
spec/models/repository_spec.rb
+0
-18
No files found.
app/models/repository.rb
View file @
d383f618
...
...
@@ -1072,19 +1072,11 @@ class Repository
end
def
cache
@cache
||=
if
is_wiki
Gitlab
::
RepositoryCache
.
new
(
self
,
extra_namespace:
'wiki'
)
else
Gitlab
::
RepositoryCache
.
new
(
self
)
end
@cache
||=
Gitlab
::
RepositoryCache
.
new
(
self
)
end
def
request_store_cache
@request_store_cache
||=
if
is_wiki
Gitlab
::
RepositoryCache
.
new
(
self
,
extra_namespace:
'wiki'
,
backend:
Gitlab
::
SafeRequestStore
)
else
Gitlab
::
RepositoryCache
.
new
(
self
,
backend:
Gitlab
::
SafeRequestStore
)
end
@request_store_cache
||=
Gitlab
::
RepositoryCache
.
new
(
self
,
backend:
Gitlab
::
SafeRequestStore
)
end
def
tags_sorted_by_committed_date
...
...
lib/gitlab/repository_cache.rb
View file @
d383f618
...
...
@@ -7,13 +7,13 @@ module Gitlab
def
initialize
(
repository
,
extra_namespace:
nil
,
backend:
Rails
.
cache
)
@repository
=
repository
@namespace
=
"
project
:
#{
repository
.
project
.
id
}
"
@namespace
=
"
#{
repository
.
full_path
}
:
#{
repository
.
project
.
id
}
"
@namespace
=
"
#{
@namespace
}
:
#{
extra_namespace
}
"
if
extra_namespace
@backend
=
backend
end
def
cache_key
(
type
)
"
#{
namespace
}
:
#{
typ
e
}
"
"
#{
type
}
:
#{
namespac
e
}
"
end
def
expire
(
key
)
...
...
spec/lib/gitlab/repository_cache_spec.rb
View file @
d383f618
...
...
@@ -4,14 +4,14 @@ describe Gitlab::RepositoryCache do
let
(
:backend
)
{
double
(
'backend'
).
as_null_object
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:repository
)
{
project
.
repository
}
let
(
:namespace
)
{
"
project
:
#{
project
.
id
}
"
}
let
(
:namespace
)
{
"
#{
repository
.
full_path
}
:
#{
project
.
id
}
"
}
let
(
:cache
)
{
described_class
.
new
(
repository
,
backend:
backend
)
}
describe
'#cache_key'
do
subject
{
cache
.
cache_key
(
:foo
)
}
it
'includes the namespace'
do
expect
(
subject
).
to
eq
"
#{
namespace
}
:foo
"
expect
(
subject
).
to
eq
"
foo:
#{
namespace
}
"
end
context
'with a given namespace'
do
...
...
@@ -22,7 +22,7 @@ describe Gitlab::RepositoryCache do
end
it
'includes the full namespace'
do
expect
(
subject
).
to
eq
"
#{
namespace
}
:
#{
extra_namespace
}
:foo
"
expect
(
subject
).
to
eq
"
foo:
#{
namespace
}
:
#{
extra_namespace
}
"
end
end
end
...
...
@@ -30,21 +30,21 @@ describe Gitlab::RepositoryCache do
describe
'#expire'
do
it
'expires the given key from the cache'
do
cache
.
expire
(
:foo
)
expect
(
backend
).
to
have_received
(
:delete
).
with
(
"
#{
namespace
}
:foo
"
)
expect
(
backend
).
to
have_received
(
:delete
).
with
(
"
foo:
#{
namespace
}
"
)
end
end
describe
'#fetch'
do
it
'fetches the given key from the cache'
do
cache
.
fetch
(
:bar
)
expect
(
backend
).
to
have_received
(
:fetch
).
with
(
"
#{
namespace
}
:bar
"
)
expect
(
backend
).
to
have_received
(
:fetch
).
with
(
"
bar:
#{
namespace
}
"
)
end
it
'accepts a block'
do
p
=
->
{}
cache
.
fetch
(
:baz
,
&
p
)
expect
(
backend
).
to
have_received
(
:fetch
).
with
(
"
#{
namespace
}
:baz
"
,
&
p
)
expect
(
backend
).
to
have_received
(
:fetch
).
with
(
"
baz:
#{
namespace
}
"
,
&
p
)
end
end
...
...
@@ -67,7 +67,7 @@ describe Gitlab::RepositoryCache do
end
it
'caches the value'
do
expect
(
backend
).
to
receive
(
:write
).
with
(
"
#{
namespace
}
:
#{
key
}
"
,
true
)
expect
(
backend
).
to
receive
(
:write
).
with
(
"
#{
key
}
:
#{
namespace
}
"
,
true
)
cache
.
fetch_without_caching_false
(
key
)
{
true
}
end
...
...
@@ -83,7 +83,7 @@ describe Gitlab::RepositoryCache do
end
it
'does not cache the value'
do
expect
(
backend
).
not_to
receive
(
:write
).
with
(
"
#{
namespace
}
:
#{
key
}
"
,
true
)
expect
(
backend
).
not_to
receive
(
:write
).
with
(
"
#{
key
}
:
#{
namespace
}
"
,
true
)
cache
.
fetch_without_caching_false
(
key
,
&
p
)
end
...
...
@@ -92,7 +92,7 @@ describe Gitlab::RepositoryCache do
context
'when the cached value is truthy'
do
before
do
backend
.
write
(
"
#{
namespace
}
:
#{
key
}
"
,
true
)
backend
.
write
(
"
#{
key
}
:
#{
namespace
}
"
,
true
)
end
it
'returns the cached value'
do
...
...
@@ -116,7 +116,7 @@ describe Gitlab::RepositoryCache do
context
'when the cached value is falsey'
do
before
do
backend
.
write
(
"
#{
namespace
}
:
#{
key
}
"
,
false
)
backend
.
write
(
"
#{
key
}
:
#{
namespace
}
"
,
false
)
end
it
'returns the result of the block'
do
...
...
@@ -126,7 +126,7 @@ describe Gitlab::RepositoryCache do
end
it
'writes the truthy value to the cache'
do
expect
(
backend
).
to
receive
(
:write
).
with
(
"
#{
namespace
}
:
#{
key
}
"
,
'block result'
)
expect
(
backend
).
to
receive
(
:write
).
with
(
"
#{
key
}
:
#{
namespace
}
"
,
'block result'
)
cache
.
fetch_without_caching_false
(
key
)
{
'block result'
}
end
...
...
spec/models/repository_spec.rb
View file @
d383f618
...
...
@@ -2400,22 +2400,4 @@ describe Repository do
repository
.
merge_base
(
'master'
,
'fix'
)
end
end
describe
'#cache'
do
subject
(
:cache
)
{
repository
.
send
(
:cache
)
}
it
'returns a RepositoryCache'
do
expect
(
subject
).
to
be_kind_of
Gitlab
::
RepositoryCache
end
it
'when is_wiki it includes wiki as part of key'
do
allow
(
repository
).
to
receive
(
:is_wiki
)
{
true
}
expect
(
subject
.
namespace
).
to
include
(
'wiki'
)
end
it
'when is_wiki is false extra_namespace is nil'
do
expect
(
subject
.
namespace
).
not_to
include
(
'wiki'
)
end
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