BUGFIX: Don't resolve oneboxes when cooking

Defer to post save job
This commit is contained in:
Sam
2014-03-18 13:12:58 +11:00
parent 24667cedee
commit 00a46253ae
2 changed files with 26 additions and 13 deletions

View File

@@ -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