A platform for community discussion. Free, open, simple.
DEV: add unique missing uploads index in post custom fields
Vinoth Kannan8d5c90014268
diff --git a/app/models/post.rb b/app/models/post.rbindex f2a93c50237..c7c57d44113 100644--- a/app/models/post.rb+++ b/app/models/post.rb@@ -1,3 +1,4 @@+# frozen_string_literal: truerequire_dependency 'pretty_text'require_dependency 'rate_limiter'require_dependency 'post_revisor'@@ -60,12 +61,15 @@ class Post < ActiveRecord::Base# We can pass several creating options to a post via attributesattr_accessor :image_sizes, :quoted_post_numbers, :no_bump, :invalidate_oneboxes, :cooking_options, :skip_unique_check, :skip_validation- LARGE_IMAGES ||= "large_images".freeze- BROKEN_IMAGES ||= "broken_images".freeze- DOWNLOADED_IMAGES ||= "downloaded_images".freeze+ LARGE_IMAGES ||= "large_images"+ BROKEN_IMAGES ||= "broken_images"+ DOWNLOADED_IMAGES ||= "downloaded_images"+ MISSING_UPLOADS ||= "missing uploads"SHORT_POST_CHARS ||= 1200+ register_custom_field_type(MISSING_UPLOADS, :json)+scope :private_posts_for_user, ->(user) {where("posts.topic_id IN (SELECT topic_idFROM topic_allowed_usersdiff --git a/db/migrate/20190410122835_add_missing_uploads_index_to_post_custom_fields.rb b/db/migrate/20190410122835_add_missing_uploads_index_to_post_custom_fields.rbnew file mode 100644index 00000000000..7cca4548ba4--- /dev/null+++ b/db/migrate/20190410122835_add_missing_uploads_index_to_post_custom_fields.rb@@ -0,0 +1,5 @@+class AddMissingUploadsIndexToPostCustomFields < ActiveRecord::Migration[5.2]+ def change+ add_index :post_custom_fields, :post_id, unique: true, where: "name = 'missing uploads'"+ end+enddiff --git a/lib/tasks/posts.rake b/lib/tasks/posts.rakeindex 083afc0750c..d01a409a944 100644--- a/lib/tasks/posts.rake+++ b/lib/tasks/posts.rake@@ -390,8 +390,7 @@ enddesc 'Finds missing post upload records from cooked HTML content'task 'posts:missing_uploads' => :environment do- name = "missing_uploads"- PostCustomField.where(name: name).destroy_all+ PostCustomField.where(name: Post::MISSING_UPLOADS).destroy_allposts = Post.have_uploads.select(:id, :cooked)count = 0@@ -409,7 +408,7 @@ task 'posts:missing_uploads' => :environment doendif missing.present?- missing.each { |src| PostCustomField.create!(post_id: post.id, name: name, value: src) }+ PostCustomField.create!(post_id: post.id, name: Post::MISSING_UPLOADS, value: missing.to_json)count += missing.countend