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
0
Merge Requests
0
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
Jérome Perrin
gitlab-ce
Commits
77798c65
Commit
77798c65
authored
May 10, 2017
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reset Repository#license memo when license file is changed
parent
08706f68
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
8 deletions
+15
-8
app/models/repository.rb
app/models/repository.rb
+13
-7
spec/models/repository_spec.rb
spec/models/repository_spec.rb
+2
-1
No files found.
app/models/repository.rb
View file @
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 @@ class Repository
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 @@ class Repository
#
# 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
View file @
77798c65
...
...
@@ -1858,11 +1858,12 @@ describe Repository, models: true do
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
...
...
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