0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-06 13:08:40 +08:00
discourse/app/jobs/regular/process_localized_cooked.rb
Natalie Tay 675a5e5be3
DEV: Add rake task to backfill localization excerpts which were empty (#36901)
This is a continuation of
https://github.com/discourse/discourse/pull/36885.

The rake task here backfills `topic_localization.excerpt` which may have
been empty (both `nil` and `""` are valid as checked on meta).

The reason why this can't be a migration is because we use
`Post.excerpt` which taps on a method in the post model which also uses
`PrettyText`.
2025-12-30 17:04:36 +08:00

31 lines
1 KiB
Ruby
Vendored

# frozen_string_literal: true
module Jobs
class ProcessLocalizedCooked < ::Jobs::Base
def execute(args)
DistributedMutex.synchronize(
"process_localized_cook_#{args[:post_localization_id]}",
validity: 10.minutes,
) do
post_localization = PostLocalization.find_by(id: args[:post_localization_id])
return if post_localization.blank?
post = post_localization.post
return if post.blank? || post.topic.blank?
processor = LocalizedCookedPostProcessor.new(post_localization, post, {})
processor.post_process
cooked = processor.html.strip
post_localization.update_column(:cooked, cooked) if cooked.present?
if post.is_first_post?
topic_localization = post.topic.localizations.find_by(locale: post_localization.locale)
topic_localization.update_excerpt(cooked:) if topic_localization
end
MessageBus.publish("/topic/#{post.topic_id}", type: :localized, id: post.id)
end
end
end
end