반응 수와 요약을 다시 생성하고 싶을 때, 이렇게 할 수 있는 방법이 있나요?
예를 들어: 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
"