A platform for community discussion. Free, open, simple.
REFACTOR: create custom field even when missing post uploads not found
Vinoth Kannana385f6c48a4b
diff --git a/app/jobs/scheduled/ensure_post_uploads_existence.rb b/app/jobs/scheduled/ensure_post_uploads_existence.rbindex 327bdddb4a8..cc3434aa680 100644--- a/app/jobs/scheduled/ensure_post_uploads_existence.rb+++ b/app/jobs/scheduled/ensure_post_uploads_existence.rb@@ -14,7 +14,7 @@ module Jobs.destroy_allPost- .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 Jobsendif 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)endendend