FIX: only save custom fields if they actually change
This commit is contained in:
parent
3ab6318e5f
commit
9c22c68d39
|
@ -49,6 +49,12 @@ module Jobs
|
||||||
start_raw = raw.dup
|
start_raw = raw.dup
|
||||||
downloaded_urls = {}
|
downloaded_urls = {}
|
||||||
large_images = post.custom_fields[LARGE_IMAGES].presence || []
|
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 = [], []
|
broken_images, new_large_images = [], []
|
||||||
|
|
||||||
extract_images_from(post.cooked).each do |image|
|
extract_images_from(post.cooked).each do |image|
|
||||||
|
@ -108,8 +114,11 @@ module Jobs
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if new_large_images.length > 0
|
||||||
post.custom_fields[LARGE_IMAGES] = large_images
|
post.custom_fields[LARGE_IMAGES] = large_images
|
||||||
post.save!
|
post.save_custom_fields
|
||||||
|
end
|
||||||
|
|
||||||
post.reload
|
post.reload
|
||||||
|
|
||||||
if start_raw == post.raw && raw != post.raw
|
if start_raw == post.raw && raw != post.raw
|
||||||
|
|
|
@ -20,6 +20,17 @@ describe Jobs::PullHotlinkedImages do
|
||||||
SiteSetting.download_remote_images_threshold = 0
|
SiteSetting.download_remote_images_threshold = 0
|
||||||
end
|
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
|
describe '#execute' do
|
||||||
before do
|
before do
|
||||||
FastImage.expects(:size).returns([100, 100]).at_least_once
|
FastImage.expects(:size).returns([100, 100]).at_least_once
|
||||||
|
|
Loading…
Reference in New Issue