diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2017-04-28 11:50:11 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2017-04-28 11:50:11 +0300 |
commit | b8dc4c761dd5277188320c74633122b8a3a3173a (patch) | |
tree | 1ea02e1d14cf6a6b2637b850b2ce37d9d8bd7a83 /app/models/member.rb | |
parent | 00e4ec55c3b8757e6d5fb8bf3176dd7e20966b3a (diff) |
Collect all users by single query when using Member#add_users
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'app/models/member.rb')
-rw-r--r-- | app/models/member.rb | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/app/models/member.rb b/app/models/member.rb index 97fba501759..7228e82e978 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -154,6 +154,11 @@ class Member < ActiveRecord::Base def add_users(source, users, access_level, current_user: nil, expires_at: nil) return [] unless users.present? + # Collect all user ids into separate array + # so we can use single sql query to get user objects + user_ids = users.select { |user| user =~ /\A\d+\Z/ } + users = users - user_ids + User.where(id: user_ids) + self.transaction do users.map do |user| add_user( |