Use excluding instead of where.not(id:

This method was added in Rails 7.0 and makes the code slihgtly more
readable.

The downside is that it generates two queries instead of one, so it
might generate some confusion when debugging SQL queries. Its impact on
performance is probably negligible.
This commit is contained in:
Javi Martín
2024-04-06 18:51:52 +02:00
parent 9841a9b03a
commit 38ad65605e
14 changed files with 19 additions and 23 deletions

View File

@@ -1,19 +1,19 @@
section "Flagging Debates & Comments" do
40.times do
debate = Debate.sample
flagger = User.where.not(id: debate.author_id).sample
flagger = User.excluding(debate.author).sample
Flag.flag(flagger, debate)
end
40.times do
comment = Comment.sample
flagger = User.where.not(id: comment.user_id).sample
flagger = User.excluding(comment.user).sample
Flag.flag(flagger, comment)
end
40.times do
proposal = Proposal.sample
flagger = User.where.not(id: proposal.author_id).sample
flagger = User.excluding(proposal.author).sample
Flag.flag(flagger, proposal)
end
end

View File

@@ -1,5 +1,5 @@
section "Voting Debates, Proposals & Comments" do
not_org_users = User.where.not(id: User.organizations)
not_org_users = User.excluding(User.organizations)
100.times do
voter = not_org_users.level_two_or_three_verified.sample
vote = [true, false].sample