# Как восстановить количество постов или реакций

**URL:** <https://meta.discourse.org/t/how-do-you-rebuild-the-post-or-reaction-count/369504>\
**Category:** Product Support\
**Created:** [10.Июнь.2025 04:43:49 UTC](https://meta.discourse.org/t/how-do-you-rebuild-the-post-or-reaction-count/369504 "2025-06-10T04:43:49Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![SubStrider](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/substrider/32/512604_2.png) [@SubStrider](https://meta.discourse.org/u/SubStrider)\
**Post date:** [10.Июнь.2025 07:32:34 UTC](https://meta.discourse.org/t/how-do-you-rebuild-the-post-or-reaction-count/369504/3 "2025-06-10T07:32:34Z")

</div>

Спасибо за ваш ответ. Я проводил тестовый импорт реакций из Xenforo в Discourse. Данные были импортированы корректно, но не отображались в сообщениях вместе с именами пользователей и прочей информацией.

Мне удалось это исправить.

 ![Screenshot 2025-06-10 at 12.58.45 PM](https://global.discourse-cdn.com/meta/original/4X/0/7/2/0723c2a4f59d9ea9f0fa91f43a87cb4e0458ba73.png)

Использовал следующий скрипт

```plaintext
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)
  end

"

```

---

_[View the full topic](https://meta.discourse.org/t/how-do-you-rebuild-the-post-or-reaction-count/369504)._
