DEV: speed up posts base imports

This commit is contained in:
Régis Hanol
2019-01-04 15:30:17 +01:00
parent 95e5f8380d
commit 788719d271
3 changed files with 54 additions and 46 deletions

View File

@@ -174,15 +174,14 @@ class PostCreator
update_user_counts
create_embedded_topic
link_post_uploads
ensure_in_allowed_users if guardian.is_staff?
unarchive_message
@post.advance_draft_sequence
@post.advance_draft_sequence unless @opts[:import_mode]
@post.save_reply_relationships
end
end
if @post && errors.blank?
if @post && errors.blank? && !@opts[:import_mode]
# update counters etc.
@post.topic.reload
@@ -194,12 +193,10 @@ class PostCreator
trigger_after_events unless opts[:skip_events]
auto_close unless @opts[:import_mode]
auto_close
end
if @post || @spam
handle_spam unless @opts[:import_mode]
end
handle_spam if !opts[:import_mode] && (@post || @spam)
@post
end
@@ -428,6 +425,8 @@ class PostCreator
end
def update_topic_auto_close
return if @opts[:import_mode]
if @topic.closed?
@topic.delete_topic_timer(TopicTimer.types[:close])
else
@@ -510,9 +509,7 @@ class PostCreator
end
def publish
return if @opts[:import_mode]
return unless @post.post_number > 1
return if @opts[:import_mode] || @post.post_number == 1
@post.publish_change_to_clients! :created
end
@@ -522,7 +519,7 @@ class PostCreator
end
def track_topic
return if @opts[:auto_track] == false
return if @opts[:import_mode] || @opts[:auto_track] == false
unless @user.user_option.disable_jump_reply?
TopicUser.change(@post.user_id,
@@ -540,8 +537,7 @@ class PostCreator
if @user.staged
TopicUser.auto_notification_for_staging(@user.id, @topic.id, TopicUser.notification_reasons[:auto_watch])
else
return if @topic.private_message?
elsif !@topic.private_message?
notification_level = @user.user_option.notification_level_when_replying || NotificationLevels.topic_levels[:tracking]
TopicUser.auto_notification(@user.id, @topic.id, TopicUser.notification_reasons[:created_post], notification_level)
end

View File

@@ -80,8 +80,8 @@ class UploadCreator
end
fixed_original_filename = nil
if is_image
if is_image
current_extension = File.extname(@filename).downcase.sub("jpeg", "jpg")
expected_extension = ".#{image_type}".downcase.sub("jpeg", "jpg")
@@ -89,11 +89,7 @@ class UploadCreator
# otherwise validation will fail and we can not save
# TODO decide if we only run the validation on the extension
if current_extension != expected_extension
basename = File.basename(@filename, current_extension)
if basename.length == 0
basename = "image"
end
basename = File.basename(@filename, current_extension).presence || "image"
fixed_original_filename = "#{basename}#{expected_extension}"
end
end
@@ -173,10 +169,7 @@ class UploadCreator
MIN_CONVERT_TO_JPEG_SAVING_RATIO = 0.70
def convert_to_jpeg!
if filesize < MIN_CONVERT_TO_JPEG_BYTES_SAVED
return
end
return if filesize < MIN_CONVERT_TO_JPEG_BYTES_SAVED
jpeg_tempfile = Tempfile.new(["image", ".jpg"])
@@ -290,7 +283,6 @@ class UploadCreator
def crop!
max_pixel_ratio = Discourse::PIXEL_RATIOS.max
filename_with_correct_ext = "image.#{@image_info.type}"
case @opts[:type]