A platform for community discussion. Free, open, simple.
FIX: properly invalidate inline oneboxes when rebaking
Régis Hanol7109d94ee77a
diff --git a/app/models/post.rb b/app/models/post.rbindex fefb43d787c..a9880a8d26d 100644--- a/app/models/post.rb+++ b/app/models/post.rb@@ -752,18 +752,16 @@ class Post < ActiveRecord::Base# Enqueue post processing for this postdef 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 != :normalJobs.enqueue(:process_post, args)DiscourseEvent.trigger(:after_trigger_post_process, self)diff --git a/app/models/post_analyzer.rb b/app/models/post_analyzer.rbindex bae36c39f86..c06d9d5f532 100644--- a/app/models/post_analyzer.rb+++ b/app/models/post_analyzer.rb@@ -33,7 +33,10 @@ class PostAnalyzerresult = 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)+ endonebox = Oneboxer.cached_onebox(url)@found_oneboxes = true if onebox.present?oneboxdiff --git a/lib/inline_oneboxer.rb b/lib/inline_oneboxer.rbindex edfd7465626..26f3ecc9ba6 100644--- a/lib/inline_oneboxer.rb+++ b/lib/inline_oneboxer.rb@@ -13,7 +13,7 @@ class InlineOneboxer@urls.map { |url| InlineOneboxer.lookup(url, @opts) }.compactend- def self.purge(url)+ def self.invalidate(url)Discourse.cache.delete(cache_key(url))end@@ -65,14 +65,8 @@ class InlineOneboxerprivatedef 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]oneboxenddiff --git a/spec/components/cooked_post_processor_spec.rb b/spec/components/cooked_post_processor_spec.rbindex aa63a7e4c8b..fef1e06aa3c 100644--- a/spec/components/cooked_post_processor_spec.rb+++ b/spec/components/cooked_post_processor_spec.rb@@ -86,7 +86,7 @@ describe CookedPostProcessor doendafter do- InlineOneboxer.purge(url)+ InlineOneboxer.invalidate(url)Oneboxer.invalidate(url)end@@ -210,7 +210,7 @@ describe CookedPostProcessor doendafter do- urls.each { |url| InlineOneboxer.purge(url) }+ urls.each { |url| InlineOneboxer.invalidate(url) }endit 'should convert the right links to inline oneboxes' dodiff --git a/spec/components/inline_oneboxer_spec.rb b/spec/components/inline_oneboxer_spec.rbindex d99bab6d425..47c5abd6bb5 100644--- a/spec/components/inline_oneboxer_spec.rb+++ b/spec/components/inline_oneboxer_spec.rb@@ -26,7 +26,7 @@ describe InlineOneboxer dofab!(:topic) { Fabricate(:topic) }before do- InlineOneboxer.purge(topic.url)+ InlineOneboxer.invalidate(topic.url)endit "puts an entry in the cache" do@@ -34,7 +34,7 @@ describe InlineOneboxer dourl = "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_blankresult = InlineOneboxer.lookup(url)@@ -49,7 +49,7 @@ describe InlineOneboxer doSiteSetting.enable_inline_onebox_on_all_domains = trueurl = "https://example.com/random-url"- InlineOneboxer.purge(url)+ InlineOneboxer.invalidate(url)expect(InlineOneboxer.cache_lookup(url)).to be_blankresult = InlineOneboxer.lookup(url)diff --git a/spec/models/post_analyzer_spec.rb b/spec/models/post_analyzer_spec.rbindex d74b72a4e1c..70addd30cd2 100644--- a/spec/models/post_analyzer_spec.rb+++ b/spec/models/post_analyzer_spec.rb@@ -31,6 +31,7 @@ describe PostAnalyzer doit 'invalidates the oneboxes for urls in the post' doOneboxer.expects(:invalidate).with url+ InlineOneboxer.expects(:invalidate).with urlpost_analyzer.cook(raw, options)endend