mirror of
https://github.com/discourse/discourse.git
synced 2026-08-06 13:08:40 +08:00
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`.
31 lines
1 KiB
Ruby
Vendored
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
|