投稿またはリアクション数を再構築するには?

リアクション数と概要を再構築したい場合、それを行う方法はありますか?

例: bundle exec rake reactions:recount

これはjobs::EnsureDbConsistencyバックグラウンドジョブでカバーされるでしょうか?

もし急いで確認して、カウントが再構築されるか確認したい場合は、/sidekiq/schedulerページから手動でトリガーできます。

ただし、なぜそれらを再計算する必要があるのか​​もう少し詳しく説明していただけると、重要な追加のコンテキストが得られるかもしれません。

「いいね!」 2

ご返信ありがとうございます。XenforoからDiscourseへのリアクションのテストインポートを行っていました。データは正しくインポートされましたが、ユーザー名などとともに投稿に表示されませんでした。

現在は完了しました。

このスクリプトを使用しました。

RAILS_ENV=production bundle exec rails runner "

  counts = DiscourseReactions::ReactionUser.group(:reaction_id).count

  DiscourseReactions::Reaction.where(id: counts.keys).find_each do |reaction|
    reaction.update_column(:reaction_users_count, counts[reaction.id])
  end

  posts_to_update = Post.where(id: DiscourseReactions::Reaction.select(:post_id).distinct)

  posts_to_update.find_each do |post|
    post_reactions = post.reactions.where('reaction_users_count > 0')

    custom_field_value = post_reactions.map do |reaction|
      {
        id: reaction.reaction_value,
        type: reaction.reaction_type,
        count: reaction.reaction_users_count
      }
    end

    if custom_field_value.present?
      post.custom_fields['discourse_reactions_reactions'] = custom_field_value.to_json
    else
      post.custom_fields.delete('discourse_reactions_reactions')
    end

    post.save_custom_fields(true)

"
「いいね!」 2