Project

General

Profile

Patch #39837 ยป optimize-query-models.patch

Go MAEDA, 2023-12-13 06:57

View differences:

app/models/group.rb
47 47
    'custom_fields',
48 48
    :if => lambda {|group, user| user.admin? && !group.builtin?})
49 49

  
50
  alias_attribute :name, :lastname
51

  
50 52
  def to_s
51 53
    name.to_s
52 54
  end
53 55

  
54
  def name
55
    lastname
56
  end
57

  
58
  def name=(arg)
59
    self.lastname = arg
60
  end
61

  
62 56
  def builtin_type
63 57
    nil
64 58
  end
app/models/issue.rb
1451 1451

  
1452 1452
  # Returns a string of css classes that apply to the issue
1453 1453
  def css_classes(user=User.current)
1454
    s = +"issue tracker-#{tracker_id} status-#{status_id} #{priority.try(:css_classes)}"
1454
    s = +"issue tracker-#{tracker_id} status-#{status_id} #{priority&.css_classes}"
1455 1455
    s << ' closed' if closed?
1456 1456
    s << ' overdue' if overdue?
1457 1457
    s << ' child' if child?
app/models/issue_query.rb
159 159
    )
160 160
    add_available_filter(
161 161
      "priority_id",
162
      :type => :list_with_history, :values => IssuePriority.all.collect{|s| [s.name, s.id.to_s]}
162
      :type => :list_with_history,
163
      :values => IssuePriority.pluck(:name, :id).map {|name, id| [name, id.to_s]}
163 164
    )
164 165
    add_available_filter(
165 166
      "author_id",
......
171 172
    )
172 173
    add_available_filter(
173 174
      "member_of_group",
174
      :type => :list_optional, :values => lambda {Group.givable.visible.collect {|g| [g.name, g.id.to_s]}}
175
      :type => :list_optional,
176
      :values => lambda {Group.givable.visible.pluck(:name, :id).map {|name, id| [name, id.to_s]}}
175 177
    )
176 178
    add_available_filter(
177 179
      "assigned_to_role",
178
      :type => :list_optional, :values => lambda {Role.givable.collect {|r| [r.name, r.id.to_s]}}
180
      :type => :list_optional,
181
      :values => lambda {Role.givable.pluck(:name, :id).map {|name, id| [name, id.to_s]}}
179 182
    )
180 183
    add_available_filter(
181 184
      "fixed_version_id",
......
195 198
    add_available_filter(
196 199
      "category_id",
197 200
      :type => :list_optional_with_history,
198
      :values => lambda {project.issue_categories.collect{|s| [s.name, s.id.to_s]}}
201
      :values => lambda {project.issue_categories.pluck(:name, :id).map {|name, id| [name, id.to_s]}}
199 202
    ) if project
200 203
    add_available_filter "subject", :type => :text
201 204
    add_available_filter "description", :type => :text
app/models/query.rb
589 589
  end
590 590

  
591 591
  def subproject_values
592
    project.descendants.visible.collect{|s| [s.name, s.id.to_s]}
592
    project.descendants.visible.pluck(:name, :id).map {|name, id| [name, id.to_s]}
593 593
  end
594 594

  
595 595
  def principals
......
651 651
    else
652 652
      statuses = IssueStatus.all.sorted
653 653
    end
654
    statuses.collect{|s| [s.name, s.id.to_s]}
654
    statuses.pluck(:name, :id).map {|name, id| [name, id.to_s]}
655 655
  end
656 656

  
657 657
  def watcher_values
......
996 996

  
997 997
      if field == 'project_id' || (self.type == 'ProjectQuery' && %w[id parent_id].include?(field))
998 998
        if v.delete('mine')
999
          v += User.current.memberships.map {|m| m.project_id.to_s}
999
          v += User.current.memberships.pluck(:project_id).map(&:to_s)
1000 1000
        end
1001 1001
        if v.delete('bookmarks')
1002 1002
          v += User.current.bookmarked_project_ids
app/models/time_entry_query.rb
80 80
      "issue.category_id",
81 81
      :type => :list_optional,
82 82
      :name => l("label_attribute_of_issue", :name => l(:field_category)),
83
      :values => lambda {project.issue_categories.collect{|s| [s.name, s.id.to_s]}}
83
      :values => lambda {project.issue_categories.pluck(:name, :id).map {|name, id| [name, id.to_s]}}
84 84
    ) if project
85 85
    add_available_filter(
86 86
      "issue.subject",
app/models/user_query.rb
45 45
      type: :list_optional, values: ->{ auth_sources_values }
46 46
    add_available_filter "is_member_of_group",
47 47
      type: :list_optional,
48
      values: ->{ Group.givable.visible.map {|g| [g.name, g.id.to_s] } }
48
      values: ->{ Group.givable.visible.pluck(:name, :id).map {|name, id| [name, id.to_s]} }
49 49
    if Setting.twofa?
50 50
      add_available_filter "twofa_scheme",
51 51
        type: :list_optional,
......
65 65
  end
66 66

  
67 67
  def auth_sources_values
68
    AuthSource.order(name: :asc).to_a.map do |auth_source|
69
      [auth_source.name, auth_source.id]
70
    end
68
    AuthSource.order(name: :asc).pluck(:name, :id)
71 69
  end
72 70

  
73 71
  def user_statuses_values
......
131 129

  
132 130
  def sql_for_is_member_of_group_field(field, operator, value)
133 131
    if ["*", "!*"].include? operator
134
      value = Group.givable.map(&:id)
132
      value = Group.givable.ids
135 133
    end
136 134

  
137 135
    e = operator.start_with?("!") ? "NOT EXISTS" : "EXISTS"
    (1-1/1)