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:
Régis Hanol 2020-06-24 11:54:54 +02:00
parent df1f804400
commit 7109d94ee7
6 changed files with 18 additions and 22 deletions

View File

@ -752,18 +752,16 @@ class Post < ActiveRecord::Base
# Enqueue post processing for this post
def trigger_post_process(bypass_bump: false, priority: :normal, new_post: false, skip_pull_hotlinked_images: false)
args = {
post_id: id,
bypass_bump: bypass_bump,
cooking_options: self.cooking_options,
new_post: new_post,
post_id: id,
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[:queue] = priority.to_s
end
args[:image_sizes] = image_sizes if self.image_sizes.present?
args[:invalidate_oneboxes] = true if self.invalidate_oneboxes.present?
args[:queue] = priority.to_s if priority && priority != :normal
Jobs.enqueue(:process_post, args)
DiscourseEvent.trigger(:after_trigger_post_process, self)

View File

@ -33,7 +33,10 @@ class PostAnalyzer
result = Oneboxer.apply(cooked) do |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)
@found_oneboxes = true if onebox.present?
onebox

View File

@ -13,7 +13,7 @@ class InlineOneboxer
@urls.map { |url| InlineOneboxer.lookup(url, @opts) }.compact
end
def self.purge(url)
def self.invalidate(url)
Discourse.cache.delete(cache_key(url))
end
@ -65,14 +65,8 @@ class InlineOneboxer
private
def self.onebox_for(url, title, opts)
onebox = {
url: url,
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 = { url: url, title: title && Emoji.gsub_emoji_to_unicode(title) }
Discourse.cache.write(cache_key(url), onebox, expires_in: 1.day) if !opts[:skip_cache]
onebox
end

View File

@ -86,7 +86,7 @@ describe CookedPostProcessor do
end
after do
InlineOneboxer.purge(url)
InlineOneboxer.invalidate(url)
Oneboxer.invalidate(url)
end
@ -210,7 +210,7 @@ describe CookedPostProcessor do
end
after do
urls.each { |url| InlineOneboxer.purge(url) }
urls.each { |url| InlineOneboxer.invalidate(url) }
end
it 'should convert the right links to inline oneboxes' do

View File

@ -26,7 +26,7 @@ describe InlineOneboxer do
fab!(:topic) { Fabricate(:topic) }
before do
InlineOneboxer.purge(topic.url)
InlineOneboxer.invalidate(topic.url)
end
it "puts an entry in the cache" do
@ -34,7 +34,7 @@ describe InlineOneboxer do
url = "https://example.com/random-url"
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
result = InlineOneboxer.lookup(url)
@ -49,7 +49,7 @@ describe InlineOneboxer do
SiteSetting.enable_inline_onebox_on_all_domains = true
url = "https://example.com/random-url"
InlineOneboxer.purge(url)
InlineOneboxer.invalidate(url)
expect(InlineOneboxer.cache_lookup(url)).to be_blank
result = InlineOneboxer.lookup(url)

View File

@ -31,6 +31,7 @@ describe PostAnalyzer do
it 'invalidates the oneboxes for urls in the post' do
Oneboxer.expects(:invalidate).with url
InlineOneboxer.expects(:invalidate).with url
post_analyzer.cook(raw, options)
end
end