Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEV: Remove query to make sure topic vote counts are deleted when topics are deleted #201

Merged
merged 2 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions db/post_migrate/20240711102255_ensure_consistency.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,6 @@ def up
SELECT '0', id, now(), now() FROM missing_ids
SQL

# remove all superflous vote count custom fields
DB.exec(<<~SQL)
DELETE FROM topic_voting_topic_vote_count
WHERE topic_id IN (
SELECT t1.id FROM topics t1
LEFT JOIN topic_voting_votes dvv
ON dvv.topic_id = t1.id
WHERE dvv.id IS NULL
)
SQL

# correct topics vote counts
DB.exec(<<~SQL)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This subsequent query is fine.

UPDATE topic_voting_topic_vote_count dvtvc
Expand Down
8 changes: 8 additions & 0 deletions spec/ensure_consistency_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,15 @@
two_vote_topic.reload
expect(two_vote_topic.topic_vote_count.votes_count).to eq(2)

# ensure deleted user has their vote deleted
user2.destroy
expect { second_vote.reload }.to raise_error(ActiveRecord::RecordNotFound)

# ensure no topic vote counts if topic doesn't exist
topic_to_delete = Fabricate(:topic)
topic_vote_count =
DiscourseTopicVoting::TopicVoteCount.create!(topic: topic_to_delete, votes_count: 10)
topic_to_delete.destroy
expect { topic_vote_count.reload }.to raise_error(ActiveRecord::RecordNotFound)
end
end