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:
parent
c672ee282a
commit
c847f5e8a1
|
@ -103,10 +103,10 @@ class About
|
||||||
ORDER BY c.position
|
ORDER BY c.position
|
||||||
SQL
|
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|
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue