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
Boxiang Sun
gitlab-ce
Commits
cc752f24
Commit
cc752f24
authored
Jul 13, 2016
by
Paco Guzman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ObjectRenderer doesn't crash when no objects to cache with Rails.cache.read_multi
parent
5fea640e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
4 deletions
+21
-4
lib/banzai/renderer.rb
lib/banzai/renderer.rb
+10
-4
spec/lib/banzai/object_renderer_spec.rb
spec/lib/banzai/object_renderer_spec.rb
+11
-0
No files found.
lib/banzai/renderer.rb
View file @
cc752f24
...
@@ -61,10 +61,16 @@ module Banzai
...
@@ -61,10 +61,16 @@ module Banzai
end
end
cacheable_items
,
non_cacheable_items
=
items_collection
.
partition
{
|
item
|
item
.
key?
(
:cache_key
)
}
cacheable_items
,
non_cacheable_items
=
items_collection
.
partition
{
|
item
|
item
.
key?
(
:cache_key
)
}
items_in_cache
=
Rails
.
cache
.
read_multi
(
*
cacheable_items
.
map
{
|
item
|
item
[
:cache_key
]
})
items_not_in_cache
=
cacheable_items
.
reject
do
|
item
|
items_in_cache
=
[]
item
[
:rendered
]
=
items_in_cache
[
item
[
:cache_key
]]
items_not_in_cache
=
[]
items_in_cache
.
key?
(
item
[
:cache_key
])
unless
cacheable_items
.
empty?
items_in_cache
=
Rails
.
cache
.
read_multi
(
*
cacheable_items
.
map
{
|
item
|
item
[
:cache_key
]
})
items_not_in_cache
=
cacheable_items
.
reject
do
|
item
|
item
[
:rendered
]
=
items_in_cache
[
item
[
:cache_key
]]
items_in_cache
.
key?
(
item
[
:cache_key
])
end
end
end
(
items_not_in_cache
+
non_cacheable_items
).
each
do
|
item
|
(
items_not_in_cache
+
non_cacheable_items
).
each
do
|
item
|
...
...
spec/lib/banzai/object_renderer_spec.rb
View file @
cc752f24
...
@@ -109,6 +109,17 @@ describe Banzai::ObjectRenderer do
...
@@ -109,6 +109,17 @@ describe Banzai::ObjectRenderer do
expect
(
docs
[
1
]).
to
be_an_instance_of
(
Nokogiri
::
HTML
::
DocumentFragment
)
expect
(
docs
[
1
]).
to
be_an_instance_of
(
Nokogiri
::
HTML
::
DocumentFragment
)
expect
(
docs
[
1
].
to_html
).
to
eq
(
'<p>bye</p>'
)
expect
(
docs
[
1
].
to_html
).
to
eq
(
'<p>bye</p>'
)
end
end
it
'returns when no objects to render'
do
objects
=
[]
renderer
=
described_class
.
new
(
project
,
user
,
pipeline: :note
)
expect
(
Banzai
).
to
receive
(
:cache_collection_render
).
with
([]).
and_call_original
expect
(
renderer
.
render_attributes
(
objects
,
:note
)).
to
eq
([])
end
end
end
describe
'#base_context'
do
describe
'#base_context'
do
...
...
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