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
696d6048
Commit
696d6048
authored
Mar 12, 2019
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab-ce master
parents
072fa180
30e52b23
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
47 additions
and
30 deletions
+47
-30
.gitlab-ci.yml
.gitlab-ci.yml
+1
-0
app/models/repository.rb
app/models/repository.rb
+2
-3
changelogs/unreleased/sh-cache-root-ref-asymetrically.yml
changelogs/unreleased/sh-cache-root-ref-asymetrically.yml
+5
-0
spec/factories/ci/pipelines.rb
spec/factories/ci/pipelines.rb
+6
-0
spec/models/repository_spec.rb
spec/models/repository_spec.rb
+33
-27
No files found.
.gitlab-ci.yml
View file @
696d6048
...
...
@@ -865,6 +865,7 @@ gitlab:ui:visual:
tags
:
-
gitlab-org
before_script
:
[]
allow_failure
:
true
dependencies
:
-
compile-assets
script
:
...
...
app/models/repository.rb
View file @
696d6048
...
...
@@ -534,10 +534,9 @@ class Repository
end
def
root_ref
# When the repo does not exist, or there is no root ref, we raise this error so no data is cached.
raw_repository
&
.
root_ref
or
raise
Gitlab
::
Git
::
Repository
::
NoRepository
# rubocop:disable Style/AndOr
raw_repository
&
.
root_ref
end
cache_method
:root_ref
cache_method
_asymmetrically
:root_ref
# Gitaly migration: https://gitlab.com/gitlab-org/gitaly/issues/314
def
exists?
...
...
changelogs/unreleased/sh-cache-root-ref-asymetrically.yml
0 → 100644
View file @
696d6048
---
title
:
Cache Repository#root_ref within a request
merge_request
:
25903
author
:
type
:
performance
spec/factories/ci/pipelines.rb
View file @
696d6048
...
...
@@ -82,6 +82,12 @@ FactoryBot.define do
end
end
trait
:with_job
do
after
(
:build
)
do
|
pipeline
,
evaluator
|
pipeline
.
builds
<<
build
(
:ci_build
,
pipeline:
pipeline
,
project:
pipeline
.
project
)
end
end
trait
:auto_devops_source
do
config_source
{
Ci
::
Pipeline
.
config_sources
[
:auto_devops_source
]
}
end
...
...
spec/models/repository_spec.rb
View file @
696d6048
...
...
@@ -1095,65 +1095,69 @@ describe Repository do
end
end
describe
'#exists?'
do
it
'returns true when a repository exists'
do
expect
(
repository
.
exists?
).
to
be
(
true
)
end
it
'returns false if no full path can be constructed'
do
allow
(
repository
).
to
receive
(
:full_path
).
and_return
(
nil
)
expect
(
repository
.
exists?
).
to
be
(
false
)
end
context
'with broken storage'
,
:broken_storage
do
it
'should raise a storage error'
do
expect_to_raise_storage_error
{
broken_repository
.
exists?
}
end
end
shared_examples
'asymmetric cached method'
do
|
method
|
context
'asymmetric caching'
,
:use_clean_rails_memory_store_caching
,
:request_store
do
let
(
:cache
)
{
repository
.
send
(
:cache
)
}
let
(
:request_store_cache
)
{
repository
.
send
(
:request_store_cache
)
}
context
'when it returns true'
do
before
do
expect
(
repository
.
raw_repository
).
to
receive
(
:exists?
).
once
.
and_return
(
true
)
expect
(
repository
.
raw_repository
).
to
receive
(
method
).
once
.
and_return
(
true
)
end
it
'caches the output in RequestStore'
do
expect
do
repository
.
exists?
end
.
to
change
{
request_store_cache
.
read
(
:exists?
)
}.
from
(
nil
).
to
(
true
)
repository
.
send
(
method
)
end
.
to
change
{
request_store_cache
.
read
(
method
)
}.
from
(
nil
).
to
(
true
)
end
it
'caches the output in RepositoryCache'
do
expect
do
repository
.
exists?
end
.
to
change
{
cache
.
read
(
:exists?
)
}.
from
(
nil
).
to
(
true
)
repository
.
send
(
method
)
end
.
to
change
{
cache
.
read
(
method
)
}.
from
(
nil
).
to
(
true
)
end
end
context
'when it returns false'
do
before
do
expect
(
repository
.
raw_repository
).
to
receive
(
:exists?
).
once
.
and_return
(
false
)
expect
(
repository
.
raw_repository
).
to
receive
(
method
).
once
.
and_return
(
false
)
end
it
'caches the output in RequestStore'
do
expect
do
repository
.
exists?
end
.
to
change
{
request_store_cache
.
read
(
:exists?
)
}.
from
(
nil
).
to
(
false
)
repository
.
send
(
method
)
end
.
to
change
{
request_store_cache
.
read
(
method
)
}.
from
(
nil
).
to
(
false
)
end
it
'does NOT cache the output in RepositoryCache'
do
expect
do
repository
.
exists?
end
.
not_to
change
{
cache
.
read
(
:exists?
)
}.
from
(
nil
)
repository
.
send
(
method
)
end
.
not_to
change
{
cache
.
read
(
method
)
}.
from
(
nil
)
end
end
end
end
describe
'#exists?'
do
it
'returns true when a repository exists'
do
expect
(
repository
.
exists?
).
to
be
(
true
)
end
it
'returns false if no full path can be constructed'
do
allow
(
repository
).
to
receive
(
:full_path
).
and_return
(
nil
)
expect
(
repository
.
exists?
).
to
be
(
false
)
end
context
'with broken storage'
,
:broken_storage
do
it
'should raise a storage error'
do
expect_to_raise_storage_error
{
broken_repository
.
exists?
}
end
end
it_behaves_like
'asymmetric cached method'
,
:exists?
end
describe
'#has_visible_content?'
do
before
do
# If raw_repository.has_visible_content? gets called more than once then
...
...
@@ -1271,6 +1275,8 @@ describe Repository do
repository
.
root_ref
repository
.
root_ref
end
it_behaves_like
'asymmetric cached method'
,
:root_ref
end
describe
'#expire_root_ref_cache'
do
...
...
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