mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 09:42:07 +08:00
BUGFIX: Don't resolve oneboxes when cooking
Defer to post save job
This commit is contained in:
parent
24667cedee
commit
00a46253ae
|
@ -11,18 +11,9 @@ class PostAnalyzer
|
|||
def cook(*args)
|
||||
cooked = PrettyText.cook(*args)
|
||||
|
||||
# cook all oneboxes, in the past we used to defer this
|
||||
# for some reason we decided to do this inline now
|
||||
# TODO: discuss on http://meta.discourse.org what the correct thing is to do
|
||||
# keep in mind some oneboxes may take a long time to build
|
||||
result = Oneboxer.apply(cooked) do |url, elem|
|
||||
Oneboxer.invalidate(url) if args.last[:invalidate_oneboxes]
|
||||
begin
|
||||
Oneboxer.onebox url
|
||||
rescue => e
|
||||
Rails.logger.warn("Failed to cook onebox: #{e.message} #{e.backtrace}")
|
||||
nil
|
||||
end
|
||||
Oneboxer.cached_onebox url
|
||||
end
|
||||
|
||||
cooked = result.to_html if result.changed?
|
||||
|
|
|
@ -22,13 +22,24 @@ module Oneboxer
|
|||
def self.preview(url, options=nil)
|
||||
options ||= {}
|
||||
Oneboxer.invalidate(url) if options[:invalidate_oneboxes]
|
||||
Onebox.preview(url, cache: Rails.cache).placeholder_html
|
||||
onebox_raw(url).placeholder_html
|
||||
end
|
||||
|
||||
def self.onebox(url, options=nil)
|
||||
options ||= {}
|
||||
Oneboxer.invalidate(url) if options[:invalidate_oneboxes]
|
||||
Onebox.preview(url, cache: Rails.cache).to_s
|
||||
onebox_raw(url).to_s
|
||||
end
|
||||
|
||||
def self.cached_onebox(url)
|
||||
Rails.cache.read(onebox_cache_key(url))
|
||||
.to_s
|
||||
end
|
||||
|
||||
def self.cached_preview(url)
|
||||
Rails.cache.read(onebox_cache_key(url))
|
||||
.try(:placeholder_html)
|
||||
.to_s
|
||||
end
|
||||
|
||||
def self.oneboxer_exists_for_url?(url)
|
||||
|
@ -36,7 +47,7 @@ module Oneboxer
|
|||
end
|
||||
|
||||
def self.invalidate(url)
|
||||
Rails.cache.delete(url)
|
||||
Rails.cache.delete(onebox_cache_key(url))
|
||||
end
|
||||
|
||||
# Parse URLs out of HTML, returning the document when finished.
|
||||
|
@ -82,5 +93,16 @@ module Oneboxer
|
|||
Result.new(doc, changed)
|
||||
end
|
||||
|
||||
private
|
||||
def self.onebox_cache_key(url)
|
||||
"onebox_#{url}"
|
||||
end
|
||||
|
||||
def self.onebox_raw(url)
|
||||
Rails.cache.fetch(onebox_cache_key(url)){
|
||||
Onebox.preview(url, cache: {})
|
||||
}
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user