FIX: only save custom fields if they actually change

This commit is contained in:
Sam 2017-11-16 15:13:15 +11:00
parent 3ab6318e5f
commit 9c22c68d39
2 changed files with 22 additions and 2 deletions

View File

@ -49,6 +49,12 @@ module Jobs
start_raw = raw.dup
downloaded_urls = {}
large_images = post.custom_fields[LARGE_IMAGES].presence || []
# recover from bad custom field silently
unless Array === large_images
large_images = []
end
broken_images, new_large_images = [], []
extract_images_from(post.cooked).each do |image|
@ -108,8 +114,11 @@ module Jobs
end
post.custom_fields[LARGE_IMAGES] = large_images
post.save!
if new_large_images.length > 0
post.custom_fields[LARGE_IMAGES] = large_images
post.save_custom_fields
end
post.reload
if start_raw == post.raw && raw != post.raw

View File

@ -20,6 +20,17 @@ describe Jobs::PullHotlinkedImages do
SiteSetting.download_remote_images_threshold = 0
end
describe "#nochange" do
it 'does saves nothing if there are no large images to pull' do
post = Fabricate(:post, raw: 'bob bob')
orig = post.updated_at
freeze_time 1.week.from_now
Jobs::PullHotlinkedImages.new.execute(post_id: post.id)
expect(orig).to be_within(1.second).of(post.reload.updated_at)
end
end
describe '#execute' do
before do
FastImage.expects(:size).returns([100, 100]).at_least_once