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

@@ -164,7 +164,7 @@ class ProposalsController < ApplicationController
.sort_by_confidence_score
.limit(Setting["featured_proposals_number"])
if @featured_proposals.present?
@resources = @resources.where.not(id: @featured_proposals)
@resources = @resources.excluding(@featured_proposals)
end
end
end