diff options
author | Go MAEDA <maeda@farend.jp> | 2021-03-19 05:20:48 +0000 |
---|---|---|
committer | Go MAEDA <maeda@farend.jp> | 2021-03-19 05:20:48 +0000 |
commit | 7c7d29e33c6f98d0b81f0055be5d6417d677a207 (patch) | |
tree | 48424d37b59f5b6f269efce6dde02abd4aba5939 /app/models/query.rb | |
parent | a18b8397ffb64a34b2db191a9161095bc317450b (diff) | |
download | redmine-7c7d29e33c6f98d0b81f0055be5d6417d677a207.tar.gz redmine-7c7d29e33c6f98d0b81f0055be5d6417d677a207.zip |
Unnecessary database access when IssueQuery class is defined (#33290).
Patch by Kevin Fischer.
git-svn-id: http://svn.redmine.org/redmine/trunk@20830 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/query.rb')
-rw-r--r-- | app/models/query.rb | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/app/models/query.rb b/app/models/query.rb index dc610f41e..308d553c2 100644 --- a/app/models/query.rb +++ b/app/models/query.rb @@ -20,17 +20,15 @@ require 'redmine/sort_criteria' class QueryColumn - attr_accessor :name, :groupable, :totalable, :default_order - attr_writer :sortable + attr_accessor :name, :totalable, :default_order + attr_writer :sortable, :groupable + include Redmine::I18n def initialize(name, options={}) self.name = name self.sortable = options[:sortable] self.groupable = options[:groupable] || false - if groupable == true - self.groupable = name.to_s - end self.totalable = options[:totalable] || false self.default_order = options[:default_order] @inline = options.key?(:inline) ? options[:inline] : true @@ -49,6 +47,10 @@ class QueryColumn end end + def groupable? + @groupable + end + # Returns true if the column is sortable, otherwise false def sortable? @sortable.present? @@ -82,13 +84,19 @@ class QueryColumn def css_classes name end + + def group_by_statement + name.to_s + end end class TimestampQueryColumn < QueryColumn - def groupable - if @groupable - Redmine::Database.timestamp_to_date(sortable, User.current.time_zone) - end + def groupable? + group_by_statement.present? + end + + def group_by_statement + Redmine::Database.timestamp_to_date(sortable, User.current.time_zone) end def group_value(object) @@ -121,12 +129,19 @@ class QueryCustomFieldColumn < QueryColumn def initialize(custom_field, options={}) self.name = "cf_#{custom_field.id}".to_sym self.sortable = custom_field.order_statement || false - self.groupable = custom_field.group_statement || false self.totalable = options.key?(:totalable) ? !!options[:totalable] : custom_field.totalable? @inline = custom_field.full_width_layout? ? false : true @cf = custom_field end + def groupable? + group_by_statement.present? + end + + def group_by_statement + @cf.group_statement + end + def caption @cf.name end @@ -741,7 +756,7 @@ class Query < ActiveRecord::Base # Returns an array of columns that can be used to group the results def groupable_columns - available_columns.select {|c| c.groupable} + available_columns.select(&:groupable?) end # Returns a Hash of columns and the key for sorting @@ -889,11 +904,11 @@ class Query < ActiveRecord::Base end def group_by_column - groupable_columns.detect {|c| c.groupable && c.name.to_s == group_by} + groupable_columns.detect {|c| c.groupable? && c.name.to_s == group_by} end def group_by_statement - group_by_column.try(:groupable) + group_by_column.try(:group_by_statement) end def project_statement |