]> source.dussan.org Git - redmine.git/commitdiff
"has been" and "has never been" filter operators can be very slow (#38527, #38788).
authorGo MAEDA <maeda@farend.jp>
Fri, 30 Jun 2023 09:40:23 +0000 (09:40 +0000)
committerGo MAEDA <maeda@farend.jp>
Fri, 30 Jun 2023 09:40:23 +0000 (09:40 +0000)
Patch by Go MAEDA.

git-svn-id: https://svn.redmine.org/redmine/trunk@22271 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/query.rb

index 117f6e226e193485bbff0190fe150781602ac69e..c099322032366504bcd610d189c139dcfdbb3bf1 100644 (file)
@@ -1458,11 +1458,13 @@ class Query < ActiveRecord::Base
           " AND " +
           queried_class.send(:sanitize_sql_for_conditions, ["#{JournalDetail.table_name}.old_value IN (?)", value.map(&:to_s)]) +
           ")"
-        if %w[ev !ev].include?(operator)
-          subquery <<
+        sql_ev =
+          if %w[ev !ev].include?(operator)
             " OR " + queried_class.send(:sanitize_sql_for_conditions, ["#{db_table}.#{db_field} IN (?)", value.map(&:to_s)])
-        end
-        sql = "#{neg} EXISTS (#{subquery})"
+          else
+            ''
+          end
+        sql = "#{neg} (EXISTS (#{subquery})#{sql_ev})"
       else
         sql = '1=0'
       end