do not bump posts when rebaking
This commit is contained in:
parent
bcfbacec16
commit
f65cde3cda
|
@ -10,12 +10,10 @@ module Jobs
|
|||
# two levels of deletion
|
||||
return unless post.present? && post.topic.present?
|
||||
|
||||
if args[:cook].present?
|
||||
post.update_column(:cooked, post.cook(post.raw, topic_id: post.topic_id))
|
||||
end
|
||||
post.update_column(:cooked, post.cook(post.raw, topic_id: post.topic_id)) if args[:cook].present?
|
||||
|
||||
cp = CookedPostProcessor.new(post, args)
|
||||
cp.post_process
|
||||
cp.post_process(args[:bypass_bump])
|
||||
|
||||
# If we changed the document, save it
|
||||
post.update_column(:cooked, cp.html) if cp.dirty?
|
||||
|
|
|
@ -69,10 +69,8 @@ module Jobs
|
|||
|
||||
# TODO: make sure the post hasn´t changed while we were downloading remote images
|
||||
if raw != post.raw
|
||||
options = {
|
||||
force_new_version: true,
|
||||
edit_reason: I18n.t("upload.edit_reason")
|
||||
}
|
||||
options = { edit_reason: I18n.t("upload.edit_reason") }
|
||||
options[:bypass_bump] = true if args[:bypass_bump] == true
|
||||
post.revise(Discourse.system_user, raw, options)
|
||||
end
|
||||
|
||||
|
|
|
@ -353,8 +353,11 @@ class Post < ActiveRecord::Base
|
|||
end
|
||||
|
||||
# Enqueue post processing for this post
|
||||
def trigger_post_process
|
||||
args = { post_id: id }
|
||||
def trigger_post_process(bypass_bump = false)
|
||||
args = {
|
||||
post_id: id,
|
||||
bypass_bump: bypass_bump
|
||||
}
|
||||
args[:image_sizes] = image_sizes if image_sizes.present?
|
||||
args[:invalidate_oneboxes] = true if invalidate_oneboxes.present?
|
||||
Jobs.enqueue(:process_post, args)
|
||||
|
|
|
@ -16,12 +16,12 @@ class CookedPostProcessor
|
|||
@size_cache = {}
|
||||
end
|
||||
|
||||
def post_process
|
||||
def post_process(bypass_bump = false)
|
||||
keep_reverse_index_up_to_date
|
||||
post_process_images
|
||||
post_process_oneboxes
|
||||
optimize_urls
|
||||
pull_hotlinked_images
|
||||
pull_hotlinked_images(bypass_bump)
|
||||
end
|
||||
|
||||
def keep_reverse_index_up_to_date
|
||||
|
@ -210,7 +210,7 @@ class CookedPostProcessor
|
|||
end
|
||||
|
||||
|
||||
def pull_hotlinked_images
|
||||
def pull_hotlinked_images(bypass_bump = false)
|
||||
# is the job enabled?
|
||||
return unless SiteSetting.download_remote_images_to_local?
|
||||
# have we enough disk space?
|
||||
|
@ -221,7 +221,7 @@ class CookedPostProcessor
|
|||
Jobs.cancel_scheduled_job(:pull_hotlinked_images, post_id: @post.id)
|
||||
# schedule the job
|
||||
delay = SiteSetting.ninja_edit_window + 1
|
||||
Jobs.enqueue_in(delay.seconds.to_i, :pull_hotlinked_images, post_id: @post.id)
|
||||
Jobs.enqueue_in(delay.seconds.to_i, :pull_hotlinked_images, post_id: @post.id, bypass_bump: bypass_bump)
|
||||
end
|
||||
|
||||
def disable_if_low_on_disk_space
|
||||
|
|
|
@ -39,9 +39,9 @@ class PostRevisor
|
|||
end
|
||||
|
||||
def should_create_new_version?
|
||||
(@post.last_editor_id != @user.id) or
|
||||
((get_revised_at - @post.last_version_at) > SiteSetting.ninja_edit_window.to_i) or
|
||||
@opts[:force_new_version] == true
|
||||
@post.last_editor_id != @user.id ||
|
||||
get_revised_at - @post.last_version_at > SiteSetting.ninja_edit_window.to_i ||
|
||||
@opts[:force_new_version] == true
|
||||
end
|
||||
|
||||
def revise_and_create_new_version
|
||||
|
|
|
@ -16,30 +16,28 @@ def rebake_post(post,opts)
|
|||
)
|
||||
|
||||
if cooked != post.cooked
|
||||
Post.exec_sql(
|
||||
'update posts set cooked = ? where id = ?', cooked, post.id
|
||||
)
|
||||
Post.exec_sql('update posts set cooked = ? where id = ?', cooked, post.id)
|
||||
post.cooked = cooked
|
||||
putc "#"
|
||||
else
|
||||
putc "."
|
||||
end
|
||||
|
||||
# Extracts urls from the body
|
||||
TopicLink.extract_from post
|
||||
# make sure we trigger the post process
|
||||
post.trigger_post_process
|
||||
post.trigger_post_process(bypass_bump: true)
|
||||
|
||||
rescue => e
|
||||
puts "\n\nFailed to bake topic_id #{post.topic_id} post_id #{post.id} #{e}\n#{e.backtrace.join("\n")} \n\n"
|
||||
end
|
||||
|
||||
def rebake_posts(opts = {})
|
||||
RailsMultisite::ConnectionManagement.each_connection do |db|
|
||||
puts "Re baking post markdown for #{db} , changes are denoted with # , no change with ."
|
||||
puts "Re baking post markdown for #{db}, changes are denoted with #, no change with ."
|
||||
|
||||
total = 0
|
||||
Post.select([
|
||||
:id, :user_id, :cooked, :raw, :topic_id, :post_number
|
||||
]).each do |post|
|
||||
Post.find_each do |post|
|
||||
rebake_post(post,opts)
|
||||
total += 1
|
||||
end
|
||||
|
|
|
@ -308,7 +308,7 @@ describe CookedPostProcessor do
|
|||
Jobs.expects(:cancel_scheduled_job).with(:pull_hotlinked_images, post_id: post.id).once
|
||||
|
||||
delay = SiteSetting.ninja_edit_window + 1
|
||||
Jobs.expects(:enqueue_in).with(delay.seconds, :pull_hotlinked_images, post_id: post.id).once
|
||||
Jobs.expects(:enqueue_in).with(delay.seconds, :pull_hotlinked_images, post_id: post.id, bypass_bump: false).once
|
||||
|
||||
cpp.pull_hotlinked_images
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue