DEV: add unique missing uploads index in post custom fields

DEV: add unique missing uploads index in post custom fields

FEATURE: Send missing post uploads stat to prometheus

diff --git a/app/models/post.rb b/app/models/post.rb
index f2a93c5..c7c57d4 100644
--- a/app/models/post.rb
+++ b/app/models/post.rb
@@ -1,3 +1,4 @@
+# frozen_string_literal: true
 require_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 attributes
   attr_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_id
              FROM topic_allowed_users
diff --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.rb
new file mode 100644
index 0000000..7cca454
--- /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
+end
diff --git a/lib/tasks/posts.rake b/lib/tasks/posts.rake
index 083afc0..d01a409 100644
--- a/lib/tasks/posts.rake
+++ b/lib/tasks/posts.rake
@@ -390,8 +390,7 @@ end
 
 desc '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_all
   posts = Post.have_uploads.select(:id, :cooked)
   count = 0
 
@@ -409,7 +408,7 @@ task 'posts:missing_uploads' => :environment do
     end
 
     if 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.count
     end

GitHub sha: 8d5c9001

FIX: use 'freeze' method again to fix 'cant modify frozen string' error

Fix the build.