DEV: add unique missing uploads index in post custom fields

https://review.discourse.org/t/feature-send-missing-post-uploads-stat-to-prometheus/2609/6?u=vinothkannans
This commit is contained in:
Vinoth Kannan 2019-04-10 18:09:35 +05:30
parent c523a12187
commit 8d5c900142
3 changed files with 14 additions and 6 deletions

View File

@ -1,3 +1,4 @@
# frozen_string_literal: true
require_dependency 'pretty_text' require_dependency 'pretty_text'
require_dependency 'rate_limiter' require_dependency 'rate_limiter'
require_dependency 'post_revisor' require_dependency 'post_revisor'
@ -60,12 +61,15 @@ class Post < ActiveRecord::Base
# We can pass several creating options to a post via attributes # 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 attr_accessor :image_sizes, :quoted_post_numbers, :no_bump, :invalidate_oneboxes, :cooking_options, :skip_unique_check, :skip_validation
LARGE_IMAGES ||= "large_images".freeze LARGE_IMAGES ||= "large_images"
BROKEN_IMAGES ||= "broken_images".freeze BROKEN_IMAGES ||= "broken_images"
DOWNLOADED_IMAGES ||= "downloaded_images".freeze DOWNLOADED_IMAGES ||= "downloaded_images"
MISSING_UPLOADS ||= "missing uploads"
SHORT_POST_CHARS ||= 1200 SHORT_POST_CHARS ||= 1200
register_custom_field_type(MISSING_UPLOADS, :json)
scope :private_posts_for_user, ->(user) { scope :private_posts_for_user, ->(user) {
where("posts.topic_id IN (SELECT topic_id where("posts.topic_id IN (SELECT topic_id
FROM topic_allowed_users FROM topic_allowed_users

View File

@ -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

View File

@ -390,8 +390,7 @@ end
desc 'Finds missing post upload records from cooked HTML content' desc 'Finds missing post upload records from cooked HTML content'
task 'posts:missing_uploads' => :environment do task 'posts:missing_uploads' => :environment do
name = "missing_uploads" PostCustomField.where(name: Post::MISSING_UPLOADS).destroy_all
PostCustomField.where(name: name).destroy_all
posts = Post.have_uploads.select(:id, :cooked) posts = Post.have_uploads.select(:id, :cooked)
count = 0 count = 0
@ -409,7 +408,7 @@ task 'posts:missing_uploads' => :environment do
end end
if missing.present? 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 count += missing.count
end end