REFACTOR: create custom field even when missing post uploads not found

This commit is contained in:
Vinoth Kannan 2019-04-04 21:49:44 +05:30
parent 44e87372da
commit a385f6c48a

View File

@ -14,7 +14,7 @@ module Jobs
.destroy_all
Post
.joins("LEFT JOIN post_custom_fields cf ON posts.id = cf.post_id AND cf.name = 'missing_uploads'")
.joins("LEFT JOIN post_custom_fields cf ON posts.id = cf.post_id AND cf.name = '#{MISSING_UPLOADS}'")
.where("(posts.cooked LIKE '%<a %' OR posts.cooked LIKE '%<img %') AND cf.id IS NULL")
.find_in_batches(batch_size: 100) do |posts|
@ -34,11 +34,9 @@ module Jobs
end
if missing.present?
post.preloaded_custom_fields = nil
post.custom_fields[MISSING_UPLOADS] = missing
post.save_custom_fields
elsif post.custom_fields[MISSING_UPLOADS].present?
PostCustomField.find_by(post_id: post.id, name: MISSING_UPLOADS).destroy!
missing.each { |src| PostCustomField.create!(post_id: post.id, name: MISSING_UPLOADS, value: src) }
else
PostCustomField.create!(post_id: post.id, name: MISSING_UPLOADS, value: nil)
end
end
end