avoid loading project on query initialization

The knowledge, whether the query has a project associated is only required for the edit case but was determined right at query initialization. This is now changed to a lazy evaluation
pull/4154/head
Jens Ulferts 9 years ago
parent 5e4c23f204
commit 6dfd97d678
  1. 13
      app/models/query.rb

@ -49,8 +49,6 @@ class Query < ActiveRecord::Base
validate :validate_work_package_filters
after_initialize :remember_project_scope
# WARNING: sortable should not contain a column called id (except for the
# work_packages.id column). Otherwise naming collisions can happen when AR
# optimizes a query into two separate DB queries (e.g. when joining tables).
@ -143,11 +141,6 @@ class Query < ActiveRecord::Base
self.filters = [Queries::WorkPackages::Filter.new('status_id', operator: 'o', values: [''])] if filters.blank?
end
# Store the fact that project is nil (used in #editable_by?)
def remember_project_scope
@is_for_all = project.nil?
end
def validate_work_package_filters
filters.each do |filter|
unless filter.valid?
@ -170,7 +163,7 @@ class Query < ActiveRecord::Base
# Admin can edit them all and regular users can edit their private queries
return true if user.admin? || (!is_public && user_id == user.id)
# Members can not edit public queries that are for all project (only admin is allowed to)
is_public && !@is_for_all && user.allowed_to?(:manage_public_queries, project)
is_public && !for_all? && user.allowed_to?(:manage_public_queries, project)
end
def add_filter(field, operator, values)
@ -627,4 +620,8 @@ class Query < ActiveRecord::Base
def connection
self.class.connection
end
def for_all?
@for_all ||= project.nil?
end
end

Loading…
Cancel
Save