From c847f5e8a167a41b0c8b6f21872aaa239212fdb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Tue, 30 Mar 2021 23:12:53 +0200 Subject: [PATCH] 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. --- app/models/about.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/about.rb b/app/models/about.rb index 5631fbb9c9e..bf0ec3d2fb0 100644 --- a/app/models/about.rb +++ b/app/models/about.rb @@ -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