DEV: small refactor of the category_moderators method (#12550)

* DEV: small refactor of the category_moderators method

Used `index_by(&:id)` instead of `map { |u| [u.id, u] }.to_h` thanks to @cvx's recommendation.

Also renamed the `moderators` variable to not clash with method of the same name.
This commit is contained in:
Régis Hanol 2021-03-30 23:12:53 +02:00 committed by GitHub
parent c672ee282a
commit c847f5e8a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 2 deletions

View File

@ -103,10 +103,10 @@ class About
ORDER BY c.position
SQL
moderators = User.where(id: results.map(&:user_ids).flatten.uniq).map { |u| [u.id, u] }.to_h
mods = User.where(id: results.map(&:user_ids).flatten.uniq).index_by(&:id)
results.map do |row|
CategoryMods.new(row.category_id, row.user_ids.map { |id| moderators[id] })
CategoryMods.new(row.category_id, mods.values_at(*row.user_ids))
end
end