From a65ce81e250a7745d16369932605c3e4630058fd Mon Sep 17 00:00:00 2001 From: Vinoth Kannan Date: Thu, 25 Apr 2019 20:06:10 +0530 Subject: [PATCH] Don't check same upload url twice in the rake task --- lib/tasks/posts.rake | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/tasks/posts.rake b/lib/tasks/posts.rake index 7e756b7bd71..0395c755bff 100644 --- a/lib/tasks/posts.rake +++ b/lib/tasks/posts.rake @@ -413,9 +413,9 @@ task 'posts:missing_uploads' => :environment do posts.each do |post| missing_post_uploads = [] + links = Nokogiri::HTML::fragment(post.cooked).css("a/@href", "img/@src").map { |media| media.value }.uniq - Nokogiri::HTML::fragment(post.cooked).css("a/@href", "img/@src").each do |media| - src = media.value + links.each do |src| next if src.blank? || upload_patterns.none? { |pattern| src =~ pattern } src = "#{SiteSetting.force_https ? "https" : "http"}:#{src}" if src.start_with?("//") @@ -449,6 +449,7 @@ task 'posts:missing_uploads' => :environment do tmp.rewind if upload = UploadCreator.new(tmp, File.basename(path)).create_for(Discourse.system_user.id) + sha1s << upload.sha1 upload_id = upload.id DbHelper.remap(UrlHelper.absolute(src), upload.url)