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

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.

diff --git a/app/models/about.rb b/app/models/about.rb
index 5631fbb..bf0ec3d 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
 

GitHub sha: c847f5e8

This commit appears in #12550 which was approved by CvX. It was merged by ZogStriP.