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:
parent
c523a12187
commit
8d5c900142
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue