From 35ce4696e769c400cc7fcf36aa26e51e7e592afc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20G=C3=BCnther?= Date: Tue, 16 Apr 2024 20:59:30 +0200 Subject: [PATCH 1/2] Remove duplicate filters in BaseQuery#where https://github.com/opf/openproject/pull/15162#issuecomment-2049061360 --- app/models/queries/base_query.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/models/queries/base_query.rb b/app/models/queries/base_query.rb index e7c5b6bbc500..848ac1323d37 100644 --- a/app/models/queries/base_query.rb +++ b/app/models/queries/base_query.rb @@ -88,11 +88,17 @@ def where(attribute, operator, values) filter.values = values filter.context = context + # Remove any previous instances of the same filter + remove_filter(filter.name) filters << filter self end + def remove_filter(name) + filters.delete(find_active_filter(name)) + end + def select(*select_values, add_not_existing: true) select_values.each do |select_value| select_column = select_for(select_value) From 5a428192b0853083132a306b2837012ac0b8d7e4 Mon Sep 17 00:00:00 2001 From: Klaus Zanders Date: Thu, 18 Apr 2024 09:42:36 +0200 Subject: [PATCH 2/2] Remove hack to have unique filter count --- app/components/filters_component.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/app/components/filters_component.rb b/app/components/filters_component.rb index 12ec01fbb0d0..c35e9a3c5a2f 100644 --- a/app/components/filters_component.rb +++ b/app/components/filters_component.rb @@ -58,11 +58,7 @@ def allowed_filters end def filters_count - @filters_count ||= query - .filters - .map(&:class) - .uniq - .count + @filters_count ||= query.filters.count end protected