Skip to content

Instantly share code, notes, and snippets.

@caio-nas
Last active April 6, 2022 02:24
Show Gist options
  • Save caio-nas/a7390e31e3449037226f0e6382cc926b to your computer and use it in GitHub Desktop.
Save caio-nas/a7390e31e3449037226f0e6382cc926b to your computer and use it in GitHub Desktop.
query comparison script
community_ids = [247, 14, 1, 13, 8, 4, 7]
query = Comment.where(
context_type: 'Community', context_id: community_ids
).where.not(
commentable_id: nil, commentable_type: nil
).select(:id, :commentable_id, :commentable_type, :context_id, :context_type)
.includes(:commentable, :context)
mismatches = query.find_each.with_object([]) do |comment, mismatches|
next if comment.commentable.blank?
commentable_id = comment.commentable_id
ct = Comment.find_by(
id: comment.id, commentable_id: commentable_id,
commentable_type: 'Expenses::LedgerAccount', location: Comment::Locations::EXPENSE_ACCOUNTS
)&.thread_size.to_i
lt = CommentFetcher.new(commentable_id,
'Expenses::LedgerAccount', community: comment.context,
location: Comment::Locations::EXPENSE_ACCOUNTS
).thread_size(commentable_id)
if ct != lt
mismatches << [commentable_id, ct, lt]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment