Change to use user_options.timezone in core (#1)

Change to use user_options.timezone in core (#1)

diff --git a/jobs/scheduled/check_logs_game.rb b/jobs/scheduled/check_logs_game.rb
index a4230e9..d597cb5 100644
--- a/jobs/scheduled/check_logs_game.rb
+++ b/jobs/scheduled/check_logs_game.rb
@@ -95,9 +95,7 @@ module Jobs
       end
 
       def user_tzinfo(user_id)
-        timezone = UserCustomField
-          .where(user_id: user_id, name: "timezone")
-          .pluck("value").first || "UTC"
+        timezone = UserOption.select(:timezone).find(user_id).timezone || "UTC"
 
         tzinfo = nil
         begin
diff --git a/spec/check_logs_game_spec.rb b/spec/check_logs_game_spec.rb
index 511d1ec..f00c4ea 100644
--- a/spec/check_logs_game_spec.rb
+++ b/spec/check_logs_game_spec.rb
@@ -31,8 +31,8 @@ describe DevAdditions::CheckPolicy do
     user2.save_custom_fields
 
     # UTC + 4
-    user3.custom_fields["timezone"] = "Asia/Baku"
-    user3.save_custom_fields
+    user3.user_option.timezone = "Asia/Baku"
+    user3.user_option.save
 
     DevAdditions::CheckPolicy.new.execute(random: false)

GitHub sha: 26db4b5f

Perhaps:

UserOption.where(user_id: user_id).pluck(:timezone).first || "UTC"

A bit shorter and faster as well.

1 Like

Robin pointed out something similar last week. When I benchmark the two locally the where is faster but not by a huge amount. Is the difference in the ActiveRecord object instantiation? Because the queries are almost identical.

Yes, plus we turbo-charge pluck for extra speed!

1 Like

Wow, nice! I have now changed this :+1:

2 Likes