DEV: wrap find_missing_uploads method in distributed mutex

And skip posts with deleted topics.\ne8fafbc123170dd1f7d2a8adea4e7810585d3e76
This commit is contained in:
Vinoth Kannan 2019-05-16 15:17:53 +05:30
parent a5a4f9dc1a
commit 56ada8374f
1 changed files with 38 additions and 34 deletions

View File

@ -919,11 +919,15 @@ class Post < ActiveRecord::Base
end end
def self.find_missing_uploads(include_local_upload: true) def self.find_missing_uploads(include_local_upload: true)
PostCustomField.where(name: Post::MISSING_UPLOADS).delete_all
missing_uploads = [] missing_uploads = []
missing_post_uploads = {} missing_post_uploads = {}
count = 0
DistributedMutex.synchronize("find_missing_uploads") do
PostCustomField.where(name: Post::MISSING_UPLOADS).delete_all
query = Post query = Post
.have_uploads .have_uploads
.joins(:topic)
.joins("LEFT JOIN post_custom_fields ON posts.id = post_custom_fields.post_id AND post_custom_fields.name = '#{Post::MISSING_UPLOADS_IGNORED}'") .joins("LEFT JOIN post_custom_fields ON posts.id = post_custom_fields.post_id AND post_custom_fields.name = '#{Post::MISSING_UPLOADS_IGNORED}'")
.where("post_custom_fields.id IS NULL") .where("post_custom_fields.id IS NULL")
.select(:id, :cooked) .select(:id, :cooked)
@ -958,7 +962,6 @@ class Post < ActiveRecord::Base
end end
end end
count = 0
missing_post_uploads = missing_post_uploads.reject do |post_id, uploads| missing_post_uploads = missing_post_uploads.reject do |post_id, uploads|
if uploads.present? if uploads.present?
PostCustomField.create!(post_id: post_id, name: Post::MISSING_UPLOADS, value: uploads.to_json) PostCustomField.create!(post_id: post_id, name: Post::MISSING_UPLOADS, value: uploads.to_json)
@ -967,6 +970,7 @@ class Post < ActiveRecord::Base
uploads.empty? uploads.empty?
end end
end
{ uploads: missing_uploads, post_uploads: missing_post_uploads, count: count } { uploads: missing_uploads, post_uploads: missing_post_uploads, count: count }
end end