Patch #21608 » project_query_speedup.patch
| app/models/custom_field.rb | ||
|---|---|---|
|
# to move in project_custom_field
|
||
|
def self.for_all
|
||
|
where(:is_for_all => true).order('position').to_a
|
||
|
RequestStore.store["#{self.class.name}_for_all"] ||= where(:is_for_all => true).order('position').to_a
|
||
|
end
|
||
|
def type_name
|
||
| plugins/easyproject/easy_plugins/easy_extensions/app/models/easy_entity_custom_attribute.rb | ||
|---|---|---|
|
return nil if entity.nil?
|
||
|
if (entity.respond_to?(:project) && @custom_field.visible_by?(entity.project, User.current)) || !entity.respond_to?(:project)
|
||
|
cv = entity.custom_values.enabled.select {|v| v.custom_field_id == @custom_field.id}
|
||
|
cv = entity.custom_values.select {|v| v.custom_field_id == @custom_field.id}
|
||
|
cv.size > 1 ? cv.sort {|a,b| a.value.to_s <=> b.value.to_s} : cv.first
|
||
|
else
|
||
|
nil
|
||
| plugins/easyproject/easy_plugins/easy_extensions/app/models/easy_queries/easy_project_query.rb | ||
|---|---|---|
|
def query_after_initialize
|
||
|
super
|
||
|
self.additional_statement = Project.allowed_to_condition(User.current, :view_project)
|
||
|
# self.additional_statement = Project.allowed_to_condition(User.current, :view_project)
|
||
|
self.display_filter_sort_on_edit = false
|
||
|
end
|
||
| ... | ... | |
|
EasyQueryColumn.new(:root),
|
||
|
EasyQueryColumn.new(:description, :sortable => "#{Project.table_name}.description"),
|
||
|
EasyQueryColumn.new(:status),
|
||
|
EasyQueryColumn.new(:author, :groupable => true, :sortable => lambda { User.fields_for_order_statement('authors') }),
|
||
|
EasyQueryColumn.new(:author, :groupable => true, :sortable => lambda { User.fields_for_order_statement('authors') }, preload: [:author]),
|
||
|
EasyQueryColumn.new(:users, :caption => :field_member),
|
||
|
EasyQueryColumn.new(:start_date),
|
||
|
EasyQueryColumn.new(:due_date),
|
||
| ... | ... | |
|
[['lft', 'asc']]
|
||
|
end
|
||
|
def default_find_preload
|
||
|
preloads = [:parent, :enabled_modules]
|
||
|
preloads << [:project_custom_fields] if has_custom_field_column?
|
||
|
preloads
|
||
|
end
|
||
|
def sortable_columns
|
||
|
{'lft' => "#{Project.table_name}.lft"}.merge(super)
|
||
|
end
|
||
| ... | ... | |
|
)
|
||
|
).join_sources
|
||
|
root_info = merge_scope(Project, options)
|
||
|
root_info = merge_scope(Project.visible, options)
|
||
|
.select('projects.id AS root_id, Count(children.id) AS children_count')
|
||
|
.joins(join_sources)
|
||
|
.where("( (#{statement}) OR (#{children_statement}) ) AND projects.parent_id IS NULL")
|
||
| plugins/easyproject/easy_plugins/easy_extensions/app/models/easy_queries/easy_query.rb | ||
|---|---|---|
|
end
|
||
|
def has_custom_field_column?
|
||
|
columns.any? { |column| column.is_a? QueryCustomFieldColumn }
|
||
|
columns.any? { |column| column.is_a? EasyQueryCustomFieldColumn }
|
||
|
end
|
||
|
def has_default_columns?
|
||