FIX: properly invalidate inline oneboxes when rebaking
When rebaking a post we were invalidating _regular_ oneboxes but not inline oneboxes. DEV: also renamed 'InlineOneboxer.purge' to 'InlineOneboxer.invalidate' to keep the API consistent with 'Oneboxer.invalidate'
This commit is contained in:
parent
df1f804400
commit
7109d94ee7
|
@ -752,18 +752,16 @@ class Post < ActiveRecord::Base
|
||||||
# Enqueue post processing for this post
|
# Enqueue post processing for this post
|
||||||
def trigger_post_process(bypass_bump: false, priority: :normal, new_post: false, skip_pull_hotlinked_images: false)
|
def trigger_post_process(bypass_bump: false, priority: :normal, new_post: false, skip_pull_hotlinked_images: false)
|
||||||
args = {
|
args = {
|
||||||
post_id: id,
|
|
||||||
bypass_bump: bypass_bump,
|
bypass_bump: bypass_bump,
|
||||||
|
cooking_options: self.cooking_options,
|
||||||
new_post: new_post,
|
new_post: new_post,
|
||||||
|
post_id: id,
|
||||||
skip_pull_hotlinked_images: skip_pull_hotlinked_images,
|
skip_pull_hotlinked_images: skip_pull_hotlinked_images,
|
||||||
}
|
}
|
||||||
args[:image_sizes] = image_sizes if image_sizes.present?
|
|
||||||
args[:invalidate_oneboxes] = true if invalidate_oneboxes.present?
|
|
||||||
args[:cooking_options] = self.cooking_options
|
|
||||||
|
|
||||||
if priority && priority != :normal
|
args[:image_sizes] = image_sizes if self.image_sizes.present?
|
||||||
args[:queue] = priority.to_s
|
args[:invalidate_oneboxes] = true if self.invalidate_oneboxes.present?
|
||||||
end
|
args[:queue] = priority.to_s if priority && priority != :normal
|
||||||
|
|
||||||
Jobs.enqueue(:process_post, args)
|
Jobs.enqueue(:process_post, args)
|
||||||
DiscourseEvent.trigger(:after_trigger_post_process, self)
|
DiscourseEvent.trigger(:after_trigger_post_process, self)
|
||||||
|
|
|
@ -33,7 +33,10 @@ class PostAnalyzer
|
||||||
|
|
||||||
result = Oneboxer.apply(cooked) do |url|
|
result = Oneboxer.apply(cooked) do |url|
|
||||||
@onebox_urls << url
|
@onebox_urls << url
|
||||||
Oneboxer.invalidate(url) if opts[:invalidate_oneboxes]
|
if opts[:invalidate_oneboxes]
|
||||||
|
Oneboxer.invalidate(url)
|
||||||
|
InlineOneboxer.invalidate(url)
|
||||||
|
end
|
||||||
onebox = Oneboxer.cached_onebox(url)
|
onebox = Oneboxer.cached_onebox(url)
|
||||||
@found_oneboxes = true if onebox.present?
|
@found_oneboxes = true if onebox.present?
|
||||||
onebox
|
onebox
|
||||||
|
|
|
@ -13,7 +13,7 @@ class InlineOneboxer
|
||||||
@urls.map { |url| InlineOneboxer.lookup(url, @opts) }.compact
|
@urls.map { |url| InlineOneboxer.lookup(url, @opts) }.compact
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.purge(url)
|
def self.invalidate(url)
|
||||||
Discourse.cache.delete(cache_key(url))
|
Discourse.cache.delete(cache_key(url))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -65,14 +65,8 @@ class InlineOneboxer
|
||||||
private
|
private
|
||||||
|
|
||||||
def self.onebox_for(url, title, opts)
|
def self.onebox_for(url, title, opts)
|
||||||
onebox = {
|
onebox = { url: url, title: title && Emoji.gsub_emoji_to_unicode(title) }
|
||||||
url: url,
|
Discourse.cache.write(cache_key(url), onebox, expires_in: 1.day) if !opts[:skip_cache]
|
||||||
title: title && Emoji.gsub_emoji_to_unicode(title)
|
|
||||||
}
|
|
||||||
unless opts[:skip_cache]
|
|
||||||
Discourse.cache.write(cache_key(url), onebox, expires_in: 1.day)
|
|
||||||
end
|
|
||||||
|
|
||||||
onebox
|
onebox
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -86,7 +86,7 @@ describe CookedPostProcessor do
|
||||||
end
|
end
|
||||||
|
|
||||||
after do
|
after do
|
||||||
InlineOneboxer.purge(url)
|
InlineOneboxer.invalidate(url)
|
||||||
Oneboxer.invalidate(url)
|
Oneboxer.invalidate(url)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -210,7 +210,7 @@ describe CookedPostProcessor do
|
||||||
end
|
end
|
||||||
|
|
||||||
after do
|
after do
|
||||||
urls.each { |url| InlineOneboxer.purge(url) }
|
urls.each { |url| InlineOneboxer.invalidate(url) }
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should convert the right links to inline oneboxes' do
|
it 'should convert the right links to inline oneboxes' do
|
||||||
|
|
|
@ -26,7 +26,7 @@ describe InlineOneboxer do
|
||||||
fab!(:topic) { Fabricate(:topic) }
|
fab!(:topic) { Fabricate(:topic) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
InlineOneboxer.purge(topic.url)
|
InlineOneboxer.invalidate(topic.url)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "puts an entry in the cache" do
|
it "puts an entry in the cache" do
|
||||||
|
@ -34,7 +34,7 @@ describe InlineOneboxer do
|
||||||
url = "https://example.com/random-url"
|
url = "https://example.com/random-url"
|
||||||
stub_request(:get, url).to_return(status: 200, body: "<html><head><title>a blog</title></head></html>")
|
stub_request(:get, url).to_return(status: 200, body: "<html><head><title>a blog</title></head></html>")
|
||||||
|
|
||||||
InlineOneboxer.purge(url)
|
InlineOneboxer.invalidate(url)
|
||||||
expect(InlineOneboxer.cache_lookup(url)).to be_blank
|
expect(InlineOneboxer.cache_lookup(url)).to be_blank
|
||||||
|
|
||||||
result = InlineOneboxer.lookup(url)
|
result = InlineOneboxer.lookup(url)
|
||||||
|
@ -49,7 +49,7 @@ describe InlineOneboxer do
|
||||||
SiteSetting.enable_inline_onebox_on_all_domains = true
|
SiteSetting.enable_inline_onebox_on_all_domains = true
|
||||||
url = "https://example.com/random-url"
|
url = "https://example.com/random-url"
|
||||||
|
|
||||||
InlineOneboxer.purge(url)
|
InlineOneboxer.invalidate(url)
|
||||||
expect(InlineOneboxer.cache_lookup(url)).to be_blank
|
expect(InlineOneboxer.cache_lookup(url)).to be_blank
|
||||||
|
|
||||||
result = InlineOneboxer.lookup(url)
|
result = InlineOneboxer.lookup(url)
|
||||||
|
|
|
@ -31,6 +31,7 @@ describe PostAnalyzer do
|
||||||
|
|
||||||
it 'invalidates the oneboxes for urls in the post' do
|
it 'invalidates the oneboxes for urls in the post' do
|
||||||
Oneboxer.expects(:invalidate).with url
|
Oneboxer.expects(:invalidate).with url
|
||||||
|
InlineOneboxer.expects(:invalidate).with url
|
||||||
post_analyzer.cook(raw, options)
|
post_analyzer.cook(raw, options)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue