אם אני רוצה לבנות מחדש את ספירת התגובות והסיכום, יש דרך לעשות זאת?
כמו: bundle exec rake reactions:recount
In a Support discussion titled How do you rebuild the post or reaction count, SubStrider asked if there’s a way to recount reaction counts and summaries, referencing a potential rake task. JammyDodger suggested that the jobs::EnsureDbConsistency background job might handle this and advised manually triggering it via /sidekiq/scheduler — while also asking for context on why the recount was needed. SubStrider clarified they were testing an import of reactions from XenForo to Discourse, where data imported correctly but didn’t display properly on posts. They resolved the issue by running a custom Rails runner script that recalculates reaction_users_count for each reaction, then updates the discourse_reactions_reactions custom field on affected posts to reflect the correct counts and metadata. A screenshot was included to show the successful result. The solution involved direct database manipulation via Rails console, ensuring post-level reaction summaries were properly rebuilt after import.
אם אני רוצה לבנות מחדש את ספירת התגובות והסיכום, יש דרך לעשות זאת?
כמו: bundle exec rake reactions:recount
האם זה יכוסה על ידי עבודת הרקע jobs::EnsureDbConsistency?
אתה יכול להפעיל אותה ידנית מדף /sidekiq/scheduler שלך אם אתה רוצה להאיץ את זה ולראות אם זה בונה מחדש את הספירות שלך.
למרות שאם תוכל להיכנס קצת יותר לפירוט לגבי למה אתה צריך לחשב אותן מחדש, זה עשוי להוסיף קצת הקשר נוסף שיכול להיות חשוב.
Thank you for your response. I was doing the test import of reactions from Xenforo to Discourse. The data was correctly imported but not showing up on posts with username and all.
Have managed to do it now.
Used this script
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
"