Открыть боковую панель
nt_test133
nt_project_uxpg8lvcuq8w
Коммиты
77798c65
Коммит
77798c65
создал
Май 10, 2017
по автору
Douwe Maan
Просмотр файлов
Reset Repository#license memo when license file is changed
владелец
08706f68
Изменения
2
Скрыть пробелы
Построчно
Рядом
app/models/repository.rb
Просмотр файла @
77798c65
...
...
@@ -30,7 +30,7 @@ class Repository
METHOD_CACHES_FOR_FILE_TYPES
=
{
readme: :rendered_readme
,
changelog: :changelog
,
license:
%i(license_blob license_key)
,
license:
%i(license_blob license_key
license
)
,
contributing: :contribution_guide
,
gitignore: :gitignore
,
koding: :koding_yml
,
...
...
@@ -42,13 +42,13 @@ class Repository
# variable.
#
# This only works for methods that do not take any arguments.
def
self
.
cache_method
(
name
,
fallback:
nil
)
def
self
.
cache_method
(
name
,
fallback:
nil
,
memoize_only:
false
)
original
=
:"_uncached_
#{
name
}
"
alias_method
(
original
,
name
)
define_method
(
name
)
do
cache_method_output
(
name
,
fallback:
fallback
)
{
__send__
(
original
)
}
cache_method_output
(
name
,
fallback:
fallback
,
memoize_only:
memoize_only
)
{
__send__
(
original
)
}
end
end
...
...
@@ -550,11 +550,11 @@ def license_key
cache_method
:license_key
def
license
return
@license
if
defined?
(
@license
)
return
unless
license_key
@license
=
Licensee
::
License
.
new
(
license_key
)
Licensee
::
License
.
new
(
license_key
)
end
cache_method
:license
,
memoize_only:
true
def
gitignore
file_on_head
(
:gitignore
)
...
...
@@ -1068,14 +1068,20 @@ def copy_gitattributes(ref)
#
# key - The name of the key to cache the data in.
# fallback - A value to fall back to in the event of a Git error.
def
cache_method_output
(
key
,
fallback:
nil
,
&
block
)
def
cache_method_output
(
key
,
fallback:
nil
,
memoize_only:
false
,
&
block
)
ivar
=
cache_instance_variable_name
(
key
)
if
instance_variable_defined?
(
ivar
)
instance_variable_get
(
ivar
)
else
begin
instance_variable_set
(
ivar
,
cache
.
fetch
(
key
,
&
block
))
value
=
if
memoize_only
yield
else
cache
.
fetch
(
key
,
&
block
)
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.
...
...
spec/models/repository_spec.rb
Просмотр файла @
77798c65
...
...
@@ -1858,11 +1858,12 @@ def merge(repository, user, merge_request, options = {})
describe
'#refresh_method_caches'
do
it
'refreshes the caches of the given types'
do
expect
(
repository
).
to
receive
(
:expire_method_caches
).
with
(
%i(rendered_readme license_blob license_key)
)
with
(
%i(rendered_readme license_blob license_key
license
)
)
expect
(
repository
).
to
receive
(
:rendered_readme
)
expect
(
repository
).
to
receive
(
:license_blob
)
expect
(
repository
).
to
receive
(
:license_key
)
expect
(
repository
).
to
receive
(
:license
)
repository
.
refresh_method_caches
(
%i(readme license)
)
end
...
...
Редактирование
Предварительный просмотр
Поддерживает Markdown
0%
Попробовать снова
или
прикрепить новый файл
.
Отмена
You are about to add
0
people
to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Отмена
Пожалуйста,
зарегистрируйтесь
или
войдите
чтобы прокомментировать