mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-07 08:54:19 +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`.
29 lines
877 B
Ruby
29 lines
877 B
Ruby
# frozen_string_literal: true
|
|
|
|
desc "Backfill empty excerpts for topic localizations from post localizations"
|
|
task "topic_localizations:backfill_excerpts" => :environment do
|
|
updated = 0
|
|
scope =
|
|
TopicLocalization
|
|
.where(excerpt: [nil, ""])
|
|
.joins(:topic)
|
|
.where.not(topics: { excerpt: "" })
|
|
.includes(topic: { first_post: :localizations })
|
|
|
|
total = scope.count
|
|
puts "Found #{total} topic localizations to process"
|
|
next if total == 0
|
|
|
|
scope.find_each do |topic_localization|
|
|
post_localization =
|
|
topic_localization.topic.first_post&.localizations&.find_by(locale: topic_localization.locale)
|
|
|
|
if post_localization
|
|
topic_localization.update_excerpt(cooked: post_localization.cooked)
|
|
updated += 1
|
|
end
|
|
|
|
print "\r#{updated}/#{total} processed"
|
|
end
|
|
puts "\nDone! Updated #{updated} topic localizations."
|
|
end
|