FEATURE: Invalidate broken images cache on Rebuild HTML action

This commit is contained in:
Vinoth Kannan 2018-12-26 23:22:07 +05:30
parent 2076f371b3
commit 2b006c0429
3 changed files with 15 additions and 1 deletions

View File

@ -513,7 +513,7 @@ class PostsController < ApplicationController
guardian.ensure_can_rebake!
post = find_post_from_params
post.rebake!(invalidate_oneboxes: true)
post.rebake!(invalidate_oneboxes: true, invalidate_broken_images: true)
render body: nil
end

View File

@ -549,6 +549,11 @@ class Post < ActiveRecord::Base
update_columns(cooked: new_cooked, baked_at: Time.new, baked_version: BAKED_VERSION)
if opts.fetch(:invalidate_broken_images, false)
custom_fields.delete(BROKEN_IMAGES)
save_custom_fields
end
# Extracts urls from the body
TopicLink.extract_from(self)
QuotedPost.extract_from(self)

View File

@ -661,6 +661,15 @@ describe PostsController do
put "/posts/#{post.id}/rebake.json"
expect(response.status).to eq(200)
end
it "will invalidate broken images cache" do
sign_in(Fabricate(:moderator))
post.custom_fields[Post::BROKEN_IMAGES] = ["https://example.com/image.jpg"].to_json
post.save_custom_fields
put "/posts/#{post.id}/rebake.json"
post.reload
expect(post.custom_fields[Post::BROKEN_IMAGES]).to be_nil
end
end
end