Skip to content

Commit f65cde3

Browse files
committed
do not bump posts when rebaking
1 parent bcfbace commit f65cde3

7 files changed

Lines changed: 23 additions & 26 deletions

File tree

app/jobs/regular/process_post.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@ def execute(args)
1010
# two levels of deletion
1111
return unless post.present? && post.topic.present?
1212

13-
if args[:cook].present?
14-
post.update_column(:cooked, post.cook(post.raw, topic_id: post.topic_id))
15-
end
13+
post.update_column(:cooked, post.cook(post.raw, topic_id: post.topic_id)) if args[:cook].present?
1614

1715
cp = CookedPostProcessor.new(post, args)
18-
cp.post_process
16+
cp.post_process(args[:bypass_bump])
1917

2018
# If we changed the document, save it
2119
post.update_column(:cooked, cp.html) if cp.dirty?

app/jobs/regular/pull_hotlinked_images.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,8 @@ def execute(args)
6969

7070
# TODO: make sure the post hasn´t changed while we were downloading remote images
7171
if raw != post.raw
72-
options = {
73-
force_new_version: true,
74-
edit_reason: I18n.t("upload.edit_reason")
75-
}
72+
options = { edit_reason: I18n.t("upload.edit_reason") }
73+
options[:bypass_bump] = true if args[:bypass_bump] == true
7674
post.revise(Discourse.system_user, raw, options)
7775
end
7876

app/models/post.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,11 @@ def save_reply_relationships
353353
end
354354

355355
# Enqueue post processing for this post
356-
def trigger_post_process
357-
args = { post_id: id }
356+
def trigger_post_process(bypass_bump = false)
357+
args = {
358+
post_id: id,
359+
bypass_bump: bypass_bump
360+
}
358361
args[:image_sizes] = image_sizes if image_sizes.present?
359362
args[:invalidate_oneboxes] = true if invalidate_oneboxes.present?
360363
Jobs.enqueue(:process_post, args)

lib/cooked_post_processor.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ def initialize(post, opts={})
1616
@size_cache = {}
1717
end
1818

19-
def post_process
19+
def post_process(bypass_bump = false)
2020
keep_reverse_index_up_to_date
2121
post_process_images
2222
post_process_oneboxes
2323
optimize_urls
24-
pull_hotlinked_images
24+
pull_hotlinked_images(bypass_bump)
2525
end
2626

2727
def keep_reverse_index_up_to_date
@@ -210,7 +210,7 @@ def optimize_urls
210210
end
211211

212212

213-
def pull_hotlinked_images
213+
def pull_hotlinked_images(bypass_bump = false)
214214
# is the job enabled?
215215
return unless SiteSetting.download_remote_images_to_local?
216216
# have we enough disk space?
@@ -221,7 +221,7 @@ def pull_hotlinked_images
221221
Jobs.cancel_scheduled_job(:pull_hotlinked_images, post_id: @post.id)
222222
# schedule the job
223223
delay = SiteSetting.ninja_edit_window + 1
224-
Jobs.enqueue_in(delay.seconds.to_i, :pull_hotlinked_images, post_id: @post.id)
224+
Jobs.enqueue_in(delay.seconds.to_i, :pull_hotlinked_images, post_id: @post.id, bypass_bump: bypass_bump)
225225
end
226226

227227
def disable_if_low_on_disk_space

lib/post_revisor.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ def get_revised_at
3939
end
4040

4141
def should_create_new_version?
42-
(@post.last_editor_id != @user.id) or
43-
((get_revised_at - @post.last_version_at) > SiteSetting.ninja_edit_window.to_i) or
44-
@opts[:force_new_version] == true
42+
@post.last_editor_id != @user.id ||
43+
get_revised_at - @post.last_version_at > SiteSetting.ninja_edit_window.to_i ||
44+
@opts[:force_new_version] == true
4545
end
4646

4747
def revise_and_create_new_version

lib/tasks/posts.rake

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,28 @@ def rebake_post(post,opts)
1616
)
1717

1818
if cooked != post.cooked
19-
Post.exec_sql(
20-
'update posts set cooked = ? where id = ?', cooked, post.id
21-
)
19+
Post.exec_sql('update posts set cooked = ? where id = ?', cooked, post.id)
2220
post.cooked = cooked
2321
putc "#"
2422
else
2523
putc "."
2624
end
2725

26+
# Extracts urls from the body
2827
TopicLink.extract_from post
2928
# make sure we trigger the post process
30-
post.trigger_post_process
29+
post.trigger_post_process(bypass_bump: true)
30+
3131
rescue => e
3232
puts "\n\nFailed to bake topic_id #{post.topic_id} post_id #{post.id} #{e}\n#{e.backtrace.join("\n")} \n\n"
3333
end
3434

3535
def rebake_posts(opts = {})
3636
RailsMultisite::ConnectionManagement.each_connection do |db|
37-
puts "Re baking post markdown for #{db} , changes are denoted with # , no change with ."
37+
puts "Re baking post markdown for #{db}, changes are denoted with #, no change with ."
3838

3939
total = 0
40-
Post.select([
41-
:id, :user_id, :cooked, :raw, :topic_id, :post_number
42-
]).each do |post|
40+
Post.find_each do |post|
4341
rebake_post(post,opts)
4442
total += 1
4543
end

spec/components/cooked_post_processor_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@
308308
Jobs.expects(:cancel_scheduled_job).with(:pull_hotlinked_images, post_id: post.id).once
309309

310310
delay = SiteSetting.ninja_edit_window + 1
311-
Jobs.expects(:enqueue_in).with(delay.seconds, :pull_hotlinked_images, post_id: post.id).once
311+
Jobs.expects(:enqueue_in).with(delay.seconds, :pull_hotlinked_images, post_id: post.id, bypass_bump: false).once
312312

313313
cpp.pull_hotlinked_images
314314
end

0 commit comments

Comments
 (0)