如果我想重建反应计数和摘要,有没有办法做到?
例如:bundle exec rake reactions:recount
如果我想重建反应计数和摘要,有没有办法做到?
例如:bundle exec rake reactions:recount
这是否属于 jobs::EnsureDbConsistency 后台作业的覆盖范围?
如果您想加快速度并查看它是否为您重建计数,您可以从您的 /sidekiq/scheduler 页面手动触发它。
虽然如果您能详细说明为什么需要重新计算它们,这可能会增加一些可能很重要的额外背景信息。
感谢您的回复。我正在进行从 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)
end
\"