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