Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
6d04f378
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
6d04f378
编写于
10月 19, 2017
作者:
A
Alejandro Rodríguez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Avoid calling underlying methods on non-existing repos
This saves us Rugged/gRPC invocations
上级
00c15cc2
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
35 addition
and
8 deletion
+35
-8
app/models/repository.rb
app/models/repository.rb
+7
-2
spec/models/repository_spec.rb
spec/models/repository_spec.rb
+28
-6
未找到文件。
app/models/repository.rb
浏览文件 @
6d04f378
...
...
@@ -1031,6 +1031,10 @@ class Repository
if
instance_variable_defined?
(
ivar
)
instance_variable_get
(
ivar
)
else
# If the repository doesn't exist and a fallback was specified we return
# that value inmediately. This saves us Rugged/gRPC invocations.
return
fallback
unless
fallback
.
nil?
||
exists?
begin
value
=
if
memoize_only
...
...
@@ -1040,8 +1044,9 @@ class Repository
end
instance_variable_set
(
ivar
,
value
)
rescue
Rugged
::
ReferenceError
,
Gitlab
::
Git
::
Repository
::
NoRepository
# if e.g. HEAD or the entire repository doesn't exist we want to
# gracefully handle this and not cache anything.
# Even if the above `#exists?` check passes these errors might still
# occur (for example because of a non-existing HEAD). We want to
# gracefully handle this and not cache anything
fallback
end
end
...
...
spec/models/repository_spec.rb
浏览文件 @
6d04f378
...
...
@@ -2110,19 +2110,41 @@ describe Repository do
end
describe
'#cache_method_output'
,
:use_clean_rails_memory_store_caching
do
let
(
:fallback
)
{
10
}
context
'with a non-existing repository'
do
let
(
:value
)
do
repository
.
cache_method_output
(
:cats
,
fallback:
10
)
do
raise
Rugged
::
ReferenceError
let
(
:project
)
{
create
(
:project
)
}
# No repository
subject
do
repository
.
cache_method_output
(
:cats
,
fallback:
fallback
)
do
repository
.
cats_call_stub
end
end
it
'returns a fallback value'
do
expect
(
value
).
to
eq
(
10
)
it
'returns the fallback value'
do
expect
(
subject
).
to
eq
(
fallback
)
end
it
'avoids calling the original method'
do
expect
(
repository
).
not_to
receive
(
:cats_call_stub
)
subject
end
end
context
'with a method throwing a non-existing-repository error'
do
subject
do
repository
.
cache_method_output
(
:cats
,
fallback:
fallback
)
do
raise
Gitlab
::
Git
::
Repository
::
NoRepository
end
end
it
'returns the fallback value'
do
expect
(
subject
).
to
eq
(
fallback
)
end
it
'does not cache the data'
do
value
subject
expect
(
repository
.
instance_variable_defined?
(
:@cats
)).
to
eq
(
false
)
expect
(
repository
.
send
(
:cache
).
exist?
(
:cats
)).
to
eq
(
false
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录