mirror of
https://github.com/discourse/discourse.git
synced 2025-06-18 08:13:49 +08:00
FIX: Clear inline onebox cache when a post is rebaked (#16871)
Meta topic: https://meta.discourse.org/t/prevent-to-linkify-when-there-is-a-redirect/226964/4?u=osama.
This commit is contained in:
@ -32,15 +32,15 @@ class PostAnalyzer
|
|||||||
end
|
end
|
||||||
|
|
||||||
limit = SiteSetting.max_oneboxes_per_post
|
limit = SiteSetting.max_oneboxes_per_post
|
||||||
result = Oneboxer.apply(cooked) do |url|
|
result = Oneboxer.apply(cooked, extra_paths: ".inline-onebox-loading") do |url, element|
|
||||||
next if limit <= 0
|
|
||||||
limit -= 1
|
|
||||||
|
|
||||||
@onebox_urls << url
|
|
||||||
if opts[:invalidate_oneboxes]
|
if opts[:invalidate_oneboxes]
|
||||||
Oneboxer.invalidate(url)
|
Oneboxer.invalidate(url)
|
||||||
InlineOneboxer.invalidate(url)
|
InlineOneboxer.invalidate(url)
|
||||||
end
|
end
|
||||||
|
next if element["class"] != Oneboxer::ONEBOX_CSS_CLASS
|
||||||
|
next if limit <= 0
|
||||||
|
limit -= 1
|
||||||
|
@onebox_urls << url
|
||||||
onebox = Oneboxer.cached_onebox(url)
|
onebox = Oneboxer.cached_onebox(url)
|
||||||
@found_oneboxes = true if onebox.present?
|
@found_oneboxes = true if onebox.present?
|
||||||
onebox
|
onebox
|
||||||
|
@ -1228,6 +1228,52 @@ describe Post do
|
|||||||
post.reload
|
post.reload
|
||||||
post.rebake!
|
post.rebake!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "uses inline onebox cache by default" do
|
||||||
|
Jobs.run_immediately!
|
||||||
|
stub_request(:get, "http://testonebox.com/vvf").to_return(status: 200, body: <<~HTML)
|
||||||
|
<html><head>
|
||||||
|
<title>hello this is Testonebox!</title>
|
||||||
|
</head></html>
|
||||||
|
HTML
|
||||||
|
post = create_post(raw: <<~POST).reload
|
||||||
|
hello inline onebox http://testonebox.com/vvf
|
||||||
|
POST
|
||||||
|
expect(post.cooked).to include("hello this is Testonebox!")
|
||||||
|
|
||||||
|
stub_request(:get, "http://testonebox.com/vvf").to_return(status: 200, body: <<~HTML)
|
||||||
|
<html><head>
|
||||||
|
<title>hello this is updated Testonebox!</title>
|
||||||
|
</head></html>
|
||||||
|
HTML
|
||||||
|
post.rebake!
|
||||||
|
expect(post.reload.cooked).to include("hello this is Testonebox!")
|
||||||
|
ensure
|
||||||
|
InlineOneboxer.invalidate("http://testonebox.com/vvf")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "passing invalidate_oneboxes: true ignores inline onebox cache" do
|
||||||
|
Jobs.run_immediately!
|
||||||
|
stub_request(:get, "http://testonebox.com/vvf22").to_return(status: 200, body: <<~HTML)
|
||||||
|
<html><head>
|
||||||
|
<title>hello this is Testonebox!</title>
|
||||||
|
</head></html>
|
||||||
|
HTML
|
||||||
|
post = create_post(raw: <<~POST).reload
|
||||||
|
hello inline onebox http://testonebox.com/vvf22
|
||||||
|
POST
|
||||||
|
expect(post.cooked).to include("hello this is Testonebox!")
|
||||||
|
|
||||||
|
stub_request(:get, "http://testonebox.com/vvf22").to_return(status: 200, body: <<~HTML)
|
||||||
|
<html><head>
|
||||||
|
<title>hello this is updated Testonebox!</title>
|
||||||
|
</head></html>
|
||||||
|
HTML
|
||||||
|
post.rebake!(invalidate_oneboxes: true)
|
||||||
|
expect(post.reload.cooked).to include("hello this is updated Testonebox!")
|
||||||
|
ensure
|
||||||
|
InlineOneboxer.invalidate("http://testonebox.com/vvf22")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#set_owner" do
|
describe "#set_owner" do
|
||||||
|
Reference in New Issue
Block a user