Skip to content

A platform for community discussion. Free, open, simple.

FIX: Cache url data for failed inline oneboxes

Vinoth Kannan44d95ad5ab8c
diff --git a/app/assets/javascripts/pretty-text/inline-oneboxer.js.es6 b/app/assets/javascripts/pretty-text/inline-oneboxer.js.es6
index 7d36b0d2d4e..a7b6a99a896 100644
--- a/app/assets/javascripts/pretty-text/inline-oneboxer.js.es6
+++ b/app/assets/javascripts/pretty-text/inline-oneboxer.js.es6
@@ -10,11 +10,13 @@ export function applyInlineOneboxes(inline, ajax) {
data: { urls: Object.keys(inline) }
}).then(result => {
result["inline-oneboxes"].forEach(onebox => {
- _cache[onebox.url] = onebox;
- let links = inline[onebox.url] || [];
- links.forEach(link => {
- link.text(onebox.title);
- });
+ if (onebox.title) {
+ _cache[onebox.url] = onebox;
+ let links = inline[onebox.url] || [];
+ links.forEach(link => {
+ link.text(onebox.title);
+ });
+ }
});
});
}
diff --git a/lib/inline_oneboxer.rb b/lib/inline_oneboxer.rb
index 1ba26830165..b21a6c8fa5e 100644
--- a/lib/inline_oneboxer.rb
+++ b/lib/inline_oneboxer.rb
@@ -52,7 +52,7 @@ class InlineOneboxer
if uri.present? &&
uri.hostname.present? &&
- (always_allow || domains.include?(uri.hostname)) &&
+ (always_allow || domains.include?(uri.hostname))
title = RetrieveTitle.crawl(url)
title = nil if title && title.length < MIN_TITLE_LENGTH
return onebox_for(url, title, opts)
diff --git a/spec/components/inline_oneboxer_spec.rb b/spec/components/inline_oneboxer_spec.rb
index 1779a7fbfa9..beca526c349 100644
--- a/spec/components/inline_oneboxer_spec.rb
+++ b/spec/components/inline_oneboxer_spec.rb
@@ -39,6 +39,21 @@ describe InlineOneboxer do
expect(cached[:url]).to eq(topic.url)
expect(cached[:title]).to eq(topic.title)
end
+
+ it "puts an entry in the cache for failed onebox" do
+ SiteSetting.enable_inline_onebox_on_all_domains = true
+ url = "https://example.com/random-url"
+
+ expect(InlineOneboxer.cache_lookup(url)).to be_blank
+
+ result = InlineOneboxer.lookup(url)
+ expect(result).to be_present
+
+ cached = InlineOneboxer.cache_lookup(url)
+ expect(cached).to be_present
+ expect(cached[:url]).to eq(url)
+ expect(cached[:title]).to be_nil
+ end
end
context ".lookup" do