PERF: Move processing of inline onebox out of V8 context. (#6658)

This commit is contained in:
Guo Xiang Tan
2018-11-26 09:21:38 +08:00
committed by GitHub
parent 93d4281706
commit 57e2f4990d
12 changed files with 201 additions and 142 deletions

View File

@@ -33,6 +33,7 @@ class CookedPostProcessor
DistributedMutex.synchronize("post_process_#{@post.id}") do
DiscourseEvent.trigger(:before_post_process_cooked, @doc, @post)
post_process_oneboxes
post_process_inline_oneboxes
post_process_images
post_process_quotes
optimize_urls
@@ -575,8 +576,25 @@ class CookedPostProcessor
@doc.try(:to_html)
end
INLINE_ONEBOX_LOADING_CSS_CLASS = "inline-onebox-loading"
private
def post_process_inline_oneboxes
@doc.css(".#{INLINE_ONEBOX_LOADING_CSS_CLASS}").each do |element|
inline_onebox = InlineOneboxer.lookup(
element.attributes["href"].value,
invalidate: !!@opts[:invalidate_oneboxes]
)
if title = inline_onebox&.dig(:title)
element.children = title
end
element.remove_class(INLINE_ONEBOX_LOADING_CSS_CLASS)
end
end
def is_svg?(img)
path =
begin