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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
[#36743] use a much easier implementation by using existing methods
Tobias Dillmann222de32aacbf
diff --git a/app/models/queries/work_packages/filter/ancestor_filter.rb b/app/models/queries/work_packages/filter/ancestor_filter.rbindex f87eab18316..084fc517acf 100644--- a/app/models/queries/work_packages/filter/ancestor_filter.rb+++ b/app/models/queries/work_packages/filter/ancestor_filter.rb@@ -32,41 +32,10 @@ class Queries::WorkPackages::Filter::AncestorFilter <Queries::WorkPackages::Filter::WorkPackageFilterinclude ::Queries::WorkPackages::Filter::FilterForWpMixin- def apply_to(_query_scope)- # We are searching for all work packages that are descendants of a list of given ancestors. To do so, we use- # a recursive CTE.- cte = <<~SQL.squish- WITH RECURSIVE descendants AS (- SELECT id- FROM work_packages- WHERE id IN (:ids)- UNION ALL- SELECT wp.id- FROM work_packages wp- INNER JOIN descendants d ON wp.parent_id = d.id- )- SQL-- # We have our descendants, now we need to select them based on the chosen operator:- select = if operator_strategy.symbol == "="- # IS (OR)- # Select all descendants, including the ancestors themselves.- # Strictly speaking the ancestors should be excluded from the result, but users can easily exclude- # them by an additional filter if desired. It is more difficult the other way around.- "SELECT id FROM descendants;"- else- # IS NOT- # Exclude all descendants from the result, including the ancestors themselves.- "SELECT id FROM work_packages WHERE id NOT IN (SELECT id from descendants);"- end-- sql = ActiveRecord::Base.sanitize_sql([cte + select, { ids: no_templated_values }])-- descendants = super.find_by_sql(sql).pluck(:id)- WorkPackage.where(id: descendants)- end-def where- "1=1"+ descendant_ids = WorkPackage.find(no_templated_values).map(&:descendants).flatten.pluck(:id)+ descendant_ids.concat(no_templated_values)++ operator_strategy.sql_for_field(descendant_ids, self.class.model.table_name, :id)endend