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
1b6c663c
Commit
1b6c663c
authored
Dec 08, 2016
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix lookup of project by unknown ref when caching is enabled
parent
6d9c1d3e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
122 additions
and
4 deletions
+122
-4
changelogs/unreleased/24224-fix-project-ref-cache.yml
changelogs/unreleased/24224-fix-project-ref-cache.yml
+4
-0
lib/banzai/filter/abstract_reference_filter.rb
lib/banzai/filter/abstract_reference_filter.rb
+15
-4
spec/lib/banzai/filter/abstract_reference_filter_spec.rb
spec/lib/banzai/filter/abstract_reference_filter_spec.rb
+103
-0
No files found.
changelogs/unreleased/24224-fix-project-ref-cache.yml
0 → 100644
View file @
1b6c663c
---
title
:
Fix lookup of project by unknown ref when caching is enabled
merge_request
:
7988
author
:
lib/banzai/filter/abstract_reference_filter.rb
View file @
1b6c663c
...
@@ -254,15 +254,26 @@ module Banzai
...
@@ -254,15 +254,26 @@ module Banzai
# Returns projects for the given paths.
# Returns projects for the given paths.
def
find_projects_for_paths
(
paths
)
def
find_projects_for_paths
(
paths
)
if
RequestStore
.
active?
if
RequestStore
.
active?
to_query
=
paths
-
project_refs_cache
.
keys
cache
=
project_refs_cache
to_query
=
paths
-
cache
.
keys
unless
to_query
.
empty?
unless
to_query
.
empty?
projects_relation_for_paths
(
to_query
).
each
do
|
project
|
projects
=
projects_relation_for_paths
(
to_query
)
get_or_set_cache
(
project_refs_cache
,
project
.
path_with_namespace
)
{
project
}
found
=
[]
projects
.
each
do
|
project
|
ref
=
project
.
path_with_namespace
get_or_set_cache
(
cache
,
project
.
path_with_namespace
)
{
project
}
found
<<
ref
end
not_found
=
to_query
-
found
not_found
.
each
do
|
ref
|
get_or_set_cache
(
cache
,
ref
)
{
nil
}
end
end
end
end
project_refs_cache
.
slice
(
*
paths
).
values
cache
.
slice
(
*
paths
).
values
.
compact
else
else
projects_relation_for_paths
(
paths
)
projects_relation_for_paths
(
paths
)
end
end
...
...
spec/lib/banzai/filter/abstract_
link
_filter_spec.rb
→
spec/lib/banzai/filter/abstract_
reference
_filter_spec.rb
View file @
1b6c663c
...
@@ -32,12 +32,63 @@ describe Banzai::Filter::AbstractReferenceFilter do
...
@@ -32,12 +32,63 @@ describe Banzai::Filter::AbstractReferenceFilter do
end
end
describe
'#find_projects_for_paths'
do
describe
'#find_projects_for_paths'
do
it
'returns a list of Projects for a list of paths'
do
let
(
:doc
)
{
Nokogiri
::
HTML
.
fragment
(
''
)
}
doc
=
Nokogiri
::
HTML
.
fragment
(
''
)
let
(
:filter
)
{
described_class
.
new
(
doc
,
project:
project
)
}
filter
=
described_class
.
new
(
doc
,
project:
project
)
context
'with RequestStore disabled'
do
it
'returns a list of Projects for a list of paths'
do
expect
(
filter
.
find_projects_for_paths
([
project
.
path_with_namespace
])).
to
eq
([
project
])
end
it
"return an empty array for paths that don't exist"
do
expect
(
filter
.
find_projects_for_paths
([
'nonexistent/project'
])).
to
eq
([])
end
end
context
'with RequestStore enabled'
do
before
do
RequestStore
.
begin!
end
after
do
RequestStore
.
end!
RequestStore
.
clear!
end
it
'returns a list of Projects for a list of paths'
do
expect
(
filter
.
find_projects_for_paths
([
project
.
path_with_namespace
])).
to
eq
([
project
])
end
context
"when no project with that path exists"
do
it
"returns no value"
do
expect
(
filter
.
find_projects_for_paths
([
'nonexistent/project'
])).
to
eq
([])
end
it
"adds the ref to the project refs cache"
do
project_refs_cache
=
{}
allow
(
filter
).
to
receive
(
:project_refs_cache
).
and_return
(
project_refs_cache
)
filter
.
find_projects_for_paths
([
'nonexistent/project'
])
expect
(
project_refs_cache
).
to
eq
({
'nonexistent/project'
=>
nil
})
end
context
'when the project refs cache includes nil values'
do
before
do
# adds { 'nonexistent/project' => nil } to cache
filter
.
project_from_ref_cached
(
'nonexistent/project'
)
end
expect
(
filter
.
find_projects_for_paths
([
project
.
path_with_namespace
])).
it
"return an empty array for paths that don't exist"
do
to
eq
([
project
])
expect
(
filter
.
find_projects_for_paths
([
'nonexistent/project'
])).
to
eq
([])
end
end
end
end
end
end
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