project_query_speedup.patch

Project#allowed_to_condition - Ondřej Ezr, 2015-12-26 04:18

Download (4.19 KB)

View differences:

app/models/custom_field.rb
219 219

  
220 220
  # to move in project_custom_field
221 221
  def self.for_all
222
    where(:is_for_all => true).order('position').to_a
222
    RequestStore.store["#{self.class.name}_for_all"] ||= where(:is_for_all => true).order('position').to_a
223 223
  end
224 224

  
225 225
  def type_name
plugins/easyproject/easy_plugins/easy_extensions/app/models/easy_entity_custom_attribute.rb
20 20
    return nil if entity.nil?
21 21

  
22 22
    if (entity.respond_to?(:project) && @custom_field.visible_by?(entity.project, User.current)) || !entity.respond_to?(:project)
23
      cv = entity.custom_values.enabled.select {|v| v.custom_field_id == @custom_field.id}
23
      cv = entity.custom_values.select {|v| v.custom_field_id == @custom_field.id}
24 24
      cv.size > 1 ? cv.sort {|a,b| a.value.to_s <=> b.value.to_s} : cv.first
25 25
    else
26 26
      nil
plugins/easyproject/easy_plugins/easy_extensions/app/models/easy_queries/easy_project_query.rb
15 15

  
16 16
  def query_after_initialize
17 17
    super
18
    self.additional_statement = Project.allowed_to_condition(User.current, :view_project)
18
    # self.additional_statement = Project.allowed_to_condition(User.current, :view_project)
19 19
    self.display_filter_sort_on_edit = false
20 20
  end
21 21

  
......
96 96
          EasyQueryColumn.new(:root),
97 97
          EasyQueryColumn.new(:description, :sortable => "#{Project.table_name}.description"),
98 98
          EasyQueryColumn.new(:status),
99
          EasyQueryColumn.new(:author, :groupable => true, :sortable => lambda { User.fields_for_order_statement('authors') }),
99
          EasyQueryColumn.new(:author, :groupable => true, :sortable => lambda { User.fields_for_order_statement('authors') }, preload: [:author]),
100 100
          EasyQueryColumn.new(:users, :caption => :field_member),
101 101
          EasyQueryColumn.new(:start_date),
102 102
          EasyQueryColumn.new(:due_date),
......
168 168
    [['lft', 'asc']]
169 169
  end
170 170

  
171
  def default_find_preload
172
    preloads = [:parent, :enabled_modules]
173
    preloads << [:project_custom_fields] if has_custom_field_column?
174
    preloads
175
  end
176

  
171 177
  def sortable_columns
172 178
    {'lft' => "#{Project.table_name}.lft"}.merge(super)
173 179
  end
......
192 198
        )
193 199
    ).join_sources
194 200

  
195
    root_info = merge_scope(Project, options)
201
    root_info = merge_scope(Project.visible, options)
196 202
                    .select('projects.id AS root_id, Count(children.id) AS children_count')
197 203
                    .joins(join_sources)
198 204
                    .where("( (#{statement}) OR (#{children_statement}) ) AND projects.parent_id IS NULL")
plugins/easyproject/easy_plugins/easy_extensions/app/models/easy_queries/easy_query.rb
1231 1231
  end
1232 1232

  
1233 1233
  def has_custom_field_column?
1234
    columns.any? { |column| column.is_a? QueryCustomFieldColumn }
1234
    columns.any? { |column| column.is_a? EasyQueryCustomFieldColumn }
1235 1235
  end
1236 1236

  
1237 1237
  def has_default_columns?