From c12709ac150504bdc350fcf3de6b699f09e0442d Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Sat, 27 Dec 2025 19:28:13 +0100 Subject: [PATCH] Minor changes --- app/helpers/users/digests_helper.rb | 9 +++------ app/jobs/users/digests/calculating_job.rb | 2 +- app/jobs/users/digests/email_sending_job.rb | 4 ++-- app/models/users/digest.rb | 6 +----- 4 files changed, 7 insertions(+), 14 deletions(-) diff --git a/app/helpers/users/digests_helper.rb b/app/helpers/users/digests_helper.rb index a00b0abe..13058203 100644 --- a/app/helpers/users/digests_helper.rb +++ b/app/helpers/users/digests_helper.rb @@ -2,9 +2,6 @@ module Users module DigestsHelper - EARTH_CIRCUMFERENCE_KM = 40_075 - MOON_DISTANCE_KM = 384_400 - def distance_with_unit(distance_meters, unit) value = Users::Digest.convert_distance(distance_meters, unit).round "#{number_with_delimiter(value)} #{unit}" @@ -13,11 +10,11 @@ module Users def distance_comparison_text(distance_meters) distance_km = distance_meters.to_f / 1000 - if distance_km >= MOON_DISTANCE_KM - percentage = ((distance_km / MOON_DISTANCE_KM) * 100).round(1) + if distance_km >= Users::Digest::MOON_DISTANCE_KM + percentage = ((distance_km / Users::Digest::MOON_DISTANCE_KM) * 100).round(1) "That's #{percentage}% of the distance to the Moon!" else - percentage = ((distance_km / EARTH_CIRCUMFERENCE_KM) * 100).round(1) + percentage = ((distance_km / Users::Digest::EARTH_CIRCUMFERENCE_KM) * 100).round(1) "That's #{percentage}% of Earth's circumference!" end end diff --git a/app/jobs/users/digests/calculating_job.rb b/app/jobs/users/digests/calculating_job.rb index bf6f92c0..aaa6c5fb 100644 --- a/app/jobs/users/digests/calculating_job.rb +++ b/app/jobs/users/digests/calculating_job.rb @@ -21,6 +21,6 @@ class Users::Digests::CalculatingJob < ApplicationJob content: "#{error.message}, stacktrace: #{error.backtrace.join("\n")}" ).call rescue ActiveRecord::RecordNotFound - # User was deleted, nothing to notify + nil end end diff --git a/app/jobs/users/digests/email_sending_job.rb b/app/jobs/users/digests/email_sending_job.rb index 03e67971..dbd2665d 100644 --- a/app/jobs/users/digests/email_sending_job.rb +++ b/app/jobs/users/digests/email_sending_job.rb @@ -23,8 +23,8 @@ class Users::Digests::EmailSendingJob < ApplicationJob def should_send_email?(user, digest) return false unless user.safe_settings.digest_emails_enabled? - return false unless digest.present? - return false if digest.sent_at.present? # Already sent + return false if digest.blank? + return false if digest.sent_at.present? true end diff --git a/app/models/users/digest.rb b/app/models/users/digest.rb index e9adbd02..0c65a753 100644 --- a/app/models/users/digest.rb +++ b/app/models/users/digest.rb @@ -10,15 +10,13 @@ class Users::Digest < ApplicationRecord belongs_to :user - validates :year, presence: true - validates :period_type, presence: true + validates :year, :period_type, presence: true validates :year, uniqueness: { scope: %i[user_id period_type] } before_create :generate_sharing_uuid enum :period_type, { monthly: 0, yearly: 1 } - # Sharing methods (following Stat model pattern) def sharing_enabled? sharing_settings.try(:[], 'enabled') == true end @@ -76,8 +74,6 @@ class Users::Digest < ApplicationRecord ) end - # Helper methods for accessing digest data - # toponyms is an array like: [{'country' => 'Germany', 'cities' => [{'city' => 'Berlin'}]}] def countries_count return 0 unless toponyms.is_a?(Array)