FIX: Cache url data for failed inline oneboxes

This commit is contained in:
Vinoth Kannan 2018-11-13 01:44:20 +05:30
parent 931480f7e3
commit 44d95ad5ab
3 changed files with 23 additions and 6 deletions

View File

@ -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);
});
}
});
});
}

View File

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

View File

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