Skip to content

Commit

Permalink
use union instead of or for performance
Browse files Browse the repository at this point in the history
  • Loading branch information
ulferts committed Jan 21, 2025
1 parent 9d31c3c commit c9d35a5
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions app/models/work_packages/scopes/directly_related.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ module DirectlyRelated
def directly_related(work_package, ignored_relation: nil)
relations_without_ignored = ignored_relation ? Relation.where.not(id: ignored_relation.id) : Relation.all

where(id: relations_without_ignored.where(from_id: work_package).select(:to_id))
.or(where(id: relations_without_ignored.where(to_id: work_package).select(:from_id)))
from_id_relations = relations_without_ignored.where(from_id: work_package).select(:to_id)
to_id_relations = relations_without_ignored.where(to_id: work_package).select(:from_id)

where(arel_table[:id].in(Arel::Nodes::UnionAll.new(from_id_relations.arel, to_id_relations.arel)))
end
end
end
Expand Down

0 comments on commit c9d35a5

Please sign in to comment.