1
0
mirror of https://github.com/meineerde/redmine.git synced 2026-02-01 03:57:15 +00:00

Improve performance of TimeEntry#assignable_users by reducing SQL queries (#35927).

Patch by Go MAEDA (user:maeda).


git-svn-id: https://svn.redmine.org/redmine/trunk@23595 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Go MAEDA 2025-04-02 09:22:35 +00:00
parent d52a63675e
commit 508c1fd548

View File

@ -243,8 +243,11 @@ class TimeEntry < ApplicationRecord
def assignable_users
users = []
if project
users = project.members.active.preload(:user)
users = users.map(&:user).select{|u| u.allowed_to?(:log_time, project)}
user_ids =
project.members.active.preload(:roles).filter_map do |m|
m.roles.any? {|role| role.allowed_to?(:log_time)} ? m.user_id : nil
end.uniq
users = User.where(:id => user_ids).sorted.to_a
end
users << User.current if User.current.logged? && !users.include?(User.current)
users