From: Go MAEDA Date: Fri, 30 Jun 2023 09:40:23 +0000 (+0000) Subject: "has been" and "has never been" filter operators can be very slow (#38527, #38788). X-Git-Tag: 5.1.0~103 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=bb3662894e3a16eaad0950dc83061343efbc5125;p=redmine.git "has been" and "has never been" filter operators can be very slow (#38527, #38788). Patch by Go MAEDA. git-svn-id: https://svn.redmine.org/redmine/trunk@22271 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/models/query.rb b/app/models/query.rb index 117f6e226..c09932203 100644 --- a/app/models/query.rb +++ b/app/models/query.rb @@ -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