mirror of
https://github.com/Shopify/liquid.git
synced 2026-10-03 00:55:11 -07:00
Update resource limit handling
This commit aligns snippet tag's resource limit handling with assign tag's `assign_score_of` method where the snippet variable acts as a pointer to a block body - increasing assign score by one
This commit is contained in:
@@ -28,18 +28,12 @@ module Liquid
|
|||||||
def render_to_output_buffer(context, output)
|
def render_to_output_buffer(context, output)
|
||||||
snippet_drop = SnippetDrop.new(@body, @to, context.template_name)
|
snippet_drop = SnippetDrop.new(@body, @to, context.template_name)
|
||||||
context.scopes.last[@to] = snippet_drop
|
context.scopes.last[@to] = snippet_drop
|
||||||
context.resource_limits.increment_assign_score(assign_score_of(snippet_drop))
|
context.resource_limits.increment_assign_score(1)
|
||||||
output
|
output
|
||||||
end
|
end
|
||||||
|
|
||||||
def blank?
|
def blank?
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def assign_score_of(snippet_drop)
|
|
||||||
snippet_drop.body.nodelist.sum { |node| node.to_s.bytesize }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1081,7 +1081,7 @@ class SnippetTest < Minitest::Test
|
|||||||
def test_increment_assign_score_by_bytes_not_characters
|
def test_increment_assign_score_by_bytes_not_characters
|
||||||
t = Template.parse("{% snippet foo %}すごい{% endsnippet %}")
|
t = Template.parse("{% snippet foo %}すごい{% endsnippet %}")
|
||||||
t.render!
|
t.render!
|
||||||
assert_equal(9, t.resource_limits.assign_score)
|
assert_equal(1, t.resource_limits.assign_score)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user