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
Léo-Paul Géneau
gitlab-ce
Commits
d4d6528c
Commit
d4d6528c
authored
Jun 22, 2018
by
Imre Farkas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Expire correct method caches after HEAD changed
parent
9c321464
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
49 additions
and
12 deletions
+49
-12
app/models/repository.rb
app/models/repository.rb
+5
-1
changelogs/unreleased/44725-expire_correct_methods_after_change_head.yml
...leased/44725-expire_correct_methods_after_change_head.yml
+5
-0
lib/gitlab/repository_cache_adapter.rb
lib/gitlab/repository_cache_adapter.rb
+10
-0
spec/lib/gitlab/repository_cache_adapter_spec.rb
spec/lib/gitlab/repository_cache_adapter_spec.rb
+10
-2
spec/models/repository_spec.rb
spec/models/repository_spec.rb
+19
-9
No files found.
app/models/repository.rb
View file @
d4d6528c
...
...
@@ -283,6 +283,10 @@ class Repository
)
end
def
cached_methods
CACHED_METHODS
end
def
expire_tags_cache
expire_method_caches
(
%i(tag_names tag_count)
)
@tags
=
nil
...
...
@@ -423,7 +427,7 @@ class Repository
# Runs code after the HEAD of a repository is changed.
def
after_change_head
expire_
method_caches
(
METHOD_CACHES_FOR_FILE_TYPES
.
keys
)
expire_
all_method_caches
end
# Runs code after a repository has been forked/imported.
...
...
changelogs/unreleased/44725-expire_correct_methods_after_change_head.yml
0 → 100644
View file @
d4d6528c
---
title
:
Expire correct method caches after HEAD changed
merge_request
:
author
:
type
:
fixed
lib/gitlab/repository_cache_adapter.rb
View file @
d4d6528c
...
...
@@ -25,6 +25,11 @@ module Gitlab
raise
NotImplementedError
end
# List of cached methods. Should be overridden by the including class
def
cached_methods
raise
NotImplementedError
end
# Caches the supplied block both in a cache and in an instance variable.
#
# The cache key and instance variable are named the same way as the value of
...
...
@@ -67,6 +72,11 @@ module Gitlab
# Expires the caches of a specific set of methods
def
expire_method_caches
(
methods
)
methods
.
each
do
|
key
|
unless
cached_methods
.
include?
(
key
.
to_sym
)
Rails
.
logger
.
error
"Requested to expire non-existent method '
#{
key
}
' for Repository"
next
end
cache
.
expire
(
key
)
ivar
=
cache_instance_variable_name
(
key
)
...
...
spec/lib/gitlab/repository_cache_adapter_spec.rb
View file @
d4d6528c
...
...
@@ -67,10 +67,18 @@ describe Gitlab::RepositoryCacheAdapter do
describe
'#expire_method_caches'
do
it
'expires the caches of the given methods'
do
expect
(
cache
).
to
receive
(
:expire
).
with
(
:readme
)
expect
(
cache
).
to
receive
(
:expire
).
with
(
:re
ndered_re
adme
)
expect
(
cache
).
to
receive
(
:expire
).
with
(
:gitignore
)
repository
.
expire_method_caches
(
%i(readme gitignore)
)
repository
.
expire_method_caches
(
%i(rendered_readme gitignore)
)
end
it
'does not expire caches for non-existent methods'
do
expect
(
cache
).
not_to
receive
(
:expire
).
with
(
:nonexistent
)
expect
(
Rails
.
logger
).
to
(
receive
(
:error
).
with
(
"Requested to expire non-existent method 'nonexistent' for Repository"
))
repository
.
expire_method_caches
(
%i(nonexistent)
)
end
end
end
spec/models/repository_spec.rb
View file @
d4d6528c
...
...
@@ -1699,19 +1699,29 @@ describe Repository do
end
describe
'#after_change_head'
do
it
'flushes the
readme cache
'
do
it
'flushes the
method caches
'
do
expect
(
repository
).
to
receive
(
:expire_method_caches
).
with
([
:readme
,
:size
,
:commit_count
,
:rendered_readme
,
:contribution_guide
,
:changelog
,
:license
,
:
contributing
,
:license
_blob
,
:
license_key
,
:gitignore
,
:koding
,
:gitlab_ci
,
:koding_yml
,
:gitlab_ci_yml
,
:branch_names
,
:tag_names
,
:branch_count
,
:tag_count
,
:avatar
,
:issue_template
,
:merge_request_template
,
:xcode_config
:exists?
,
:root_ref
,
:has_visible_content?
,
:issue_template_names
,
:merge_request_template_names
,
:xcode_project?
])
repository
.
after_change_head
...
...
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