Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

use union instead of or for performance

ulferts88bd4f025709
diff --git a/app/models/work_packages/scopes/directly_related.rb b/app/models/work_packages/scopes/directly_related.rb
index b29b99cbdfa..4e351cfebb7 100644
--- a/app/models/work_packages/scopes/directly_related.rb
+++ b/app/models/work_packages/scopes/directly_related.rb
@@ -34,8 +34,10 @@ module WorkPackages::Scopes
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