mirror of
https://github.com/discourse/discourse.git
synced 2025-05-30 07:11:34 +08:00
FIX: Link post to uploads in PostCreator
.
* This ensures that uploads are linked to their post on creation instead of a background job which may be delayed if Sidekiq is facing difficulties.
This commit is contained in:
@ -35,7 +35,11 @@ class CookedPostProcessor
|
||||
post_process_oneboxes
|
||||
post_process_images
|
||||
post_process_quotes
|
||||
keep_reverse_index_up_to_date
|
||||
|
||||
unless @opts[:skip_link_post_uploads]
|
||||
@post.link_post_uploads(fragments: @doc)
|
||||
end
|
||||
|
||||
optimize_urls
|
||||
update_post_image
|
||||
enforce_nofollow
|
||||
@ -58,26 +62,6 @@ class CookedPostProcessor
|
||||
BadgeGranter.grant(Badge.find(Badge::FirstReplyByEmail), @post.user, post_id: @post.id) if @post.is_reply_by_email?
|
||||
end
|
||||
|
||||
def keep_reverse_index_up_to_date
|
||||
upload_ids = []
|
||||
|
||||
@doc.css("a/@href", "img/@src").each do |media|
|
||||
if upload = Upload.get_from_url(media.value)
|
||||
upload_ids << upload.id
|
||||
end
|
||||
end
|
||||
|
||||
upload_ids |= downloaded_images.values.select { |id| Upload.exists?(id) }
|
||||
|
||||
values = upload_ids.map { |u| "(#{@post.id},#{u})" }.join(",")
|
||||
PostUpload.transaction do
|
||||
PostUpload.where(post_id: @post.id).delete_all
|
||||
if upload_ids.size > 0
|
||||
DB.exec("INSERT INTO post_uploads (post_id, upload_id) VALUES #{values}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def post_process_images
|
||||
extract_images.each do |img|
|
||||
src = img["src"].sub(/^https?:/i, "")
|
||||
@ -159,15 +143,25 @@ class CookedPostProcessor
|
||||
end
|
||||
|
||||
def large_images
|
||||
@large_images ||= JSON.parse(@post.custom_fields[Post::LARGE_IMAGES].presence || "[]") rescue []
|
||||
@large_images ||=
|
||||
begin
|
||||
JSON.parse(@post.custom_fields[Post::LARGE_IMAGES].presence || "[]")
|
||||
rescue JSON::ParserError
|
||||
[]
|
||||
end
|
||||
end
|
||||
|
||||
def broken_images
|
||||
@broken_images ||= JSON.parse(@post.custom_fields[Post::BROKEN_IMAGES].presence || "[]") rescue []
|
||||
@broken_images ||=
|
||||
begin
|
||||
JSON.parse(@post.custom_fields[Post::BROKEN_IMAGES].presence || "[]")
|
||||
rescue JSON::ParserError
|
||||
[]
|
||||
end
|
||||
end
|
||||
|
||||
def downloaded_images
|
||||
@downloaded_images ||= JSON.parse(@post.custom_fields[Post::DOWNLOADED_IMAGES].presence || "{}") rescue {}
|
||||
@downloaded_images ||= @post.downloaded_images
|
||||
end
|
||||
|
||||
def extract_images
|
||||
|
Reference in New Issue
Block a user