Remove comments

This commit is contained in:
Eugene Burmakin 2025-12-27 13:32:33 +01:00
parent f1dbaeb2ab
commit b2becf99fb
6 changed files with 14 additions and 18 deletions

View file

@ -13,7 +13,6 @@ class Points::NightlyReverseGeocodingJob < ApplicationJob
processed_user_ids.add(point.user_id)
end
# Invalidate caches for all users who had points reverse geocoded
processed_user_ids.each do |user_id|
Cache::InvalidateUserCaches.new(user_id).call
end

View file

@ -26,7 +26,7 @@ class Stats::CalculateMonth
def start_timestamp = DateTime.new(year, month, 1).to_i
def end_timestamp
DateTime.new(year, month, -1).to_i # -1 returns last day of month
DateTime.new(year, month, -1).to_i
end
def update_month_stats(year, month)
@ -43,7 +43,6 @@ class Stats::CalculateMonth
stat.save!
# Invalidate user caches after stats calculation since they may have changed
Cache::InvalidateUserCaches.new(user.id).call
end
end

View file

@ -15,7 +15,6 @@ RSpec.describe Imports::DestroyJob, type: :job do
context 'when import exists' do
before do
# Create some points for the import
create_list(:point, 3, user: user, import: import)
end
@ -113,7 +112,6 @@ RSpec.describe Imports::DestroyJob, type: :job do
described_class.perform_now(non_existent_id)
# Early return at line 8 doesn't log, only rescue block does
expect(Rails.logger).not_to have_received(:warn)
end
end
@ -158,7 +156,9 @@ RSpec.describe Imports::DestroyJob, type: :job do
it 'has already set status to deleting before service is called' do
expect do
described_class.perform_now(import.id) rescue StandardError
described_class.perform_now(import.id)
rescue StandardError
StandardError
end.to change { import.reload.status }.to('deleting')
end
end

View file

@ -7,7 +7,6 @@ RSpec.describe Points::NightlyReverseGeocodingJob, type: :job do
let(:user) { create(:user) }
before do
# Clear any existing jobs and points to ensure test isolation
ActiveJob::Base.queue_adapter.enqueued_jobs.clear
Point.delete_all
end
@ -126,11 +125,14 @@ RSpec.describe Points::NightlyReverseGeocodingJob, type: :job do
end
it 'does not invalidate caches multiple times for the same user' do
# user has 2 points, but cache should only be invalidated once
cache_service = instance_double(Cache::InvalidateUserCaches)
allow(Cache::InvalidateUserCaches).to receive(:new).with(user.id).and_return(cache_service)
allow(Cache::InvalidateUserCaches).to receive(:new).with(user2.id).and_return(instance_double(Cache::InvalidateUserCaches, call: nil))
allow(Cache::InvalidateUserCaches).to receive(:new).with(user2.id).and_return(
instance_double(
Cache::InvalidateUserCaches, call: nil
)
)
allow(cache_service).to receive(:call)
described_class.perform_now

View file

@ -8,20 +8,17 @@ RSpec.describe Cache::InvalidateUserCaches do
describe '#call' do
it 'invalidates all user-related caches' do
# Pre-populate the caches
Rails.cache.write("dawarich/user_#{user.id}_countries_visited", ['USA', 'Canada'])
Rails.cache.write("dawarich/user_#{user.id}_countries_visited", %w[USA Canada])
Rails.cache.write("dawarich/user_#{user.id}_cities_visited", ['New York', 'Toronto'])
Rails.cache.write("dawarich/user_#{user.id}_points_geocoded_stats", { geocoded: 100, without_data: 10 })
# Verify caches are populated
expect(Rails.cache.read("dawarich/user_#{user.id}_countries_visited")).to eq(['USA', 'Canada'])
expect(Rails.cache.read("dawarich/user_#{user.id}_countries_visited")).to eq(%w[USA Canada])
expect(Rails.cache.read("dawarich/user_#{user.id}_cities_visited")).to eq(['New York', 'Toronto'])
expect(Rails.cache.read("dawarich/user_#{user.id}_points_geocoded_stats")).to eq({ geocoded: 100, without_data: 10 })
expect(Rails.cache.read("dawarich/user_#{user.id}_points_geocoded_stats")).to eq({ geocoded: 100,
without_data: 10 })
# Invalidate caches
service.call
# Verify caches are cleared
expect(Rails.cache.read("dawarich/user_#{user.id}_countries_visited")).to be_nil
expect(Rails.cache.read("dawarich/user_#{user.id}_cities_visited")).to be_nil
expect(Rails.cache.read("dawarich/user_#{user.id}_points_geocoded_stats")).to be_nil
@ -30,7 +27,7 @@ RSpec.describe Cache::InvalidateUserCaches do
describe '#invalidate_countries_visited' do
it 'deletes the countries_visited cache' do
Rails.cache.write("dawarich/user_#{user.id}_countries_visited", ['USA', 'Canada'])
Rails.cache.write("dawarich/user_#{user.id}_countries_visited", %w[USA Canada])
service.invalidate_countries_visited

View file

@ -204,7 +204,6 @@ RSpec.describe Stats::CalculateMonth do
context 'when invalidating caches' do
it 'invalidates user caches after updating stats' do
# Use existing points from the parent context
cache_service = instance_double(Cache::InvalidateUserCaches)
allow(Cache::InvalidateUserCaches).to receive(:new).with(user.id).and_return(cache_service)
allow(cache_service).to receive(:call)