mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-11 01:31:39 -05:00
Reset counters for points counter cache
This commit is contained in:
parent
02e6fb8a85
commit
b8d69a6797
5 changed files with 13 additions and 13 deletions
|
|
@ -16,12 +16,7 @@ class DataMigrations::PrefillPointsCounterCacheJob < ApplicationJob
|
||||||
private
|
private
|
||||||
|
|
||||||
def prefill_counter_for_user(user_id)
|
def prefill_counter_for_user(user_id)
|
||||||
user = User.find(user_id)
|
User.reset_counters(user_id, :points)
|
||||||
points_count = user.points.count
|
|
||||||
|
|
||||||
User.where(id: user_id).update_all(points_count: points_count)
|
|
||||||
|
|
||||||
Rails.logger.info "Updated points_count for user #{user_id}: #{points_count}"
|
|
||||||
rescue ActiveRecord::RecordNotFound
|
rescue ActiveRecord::RecordNotFound
|
||||||
Rails.logger.warn "User #{user_id} not found, skipping counter cache update"
|
Rails.logger.warn "User #{user_id} not found, skipping counter cache update"
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ class Imports::Create
|
||||||
schedule_stats_creating(user.id)
|
schedule_stats_creating(user.id)
|
||||||
schedule_visit_suggesting(user.id, import)
|
schedule_visit_suggesting(user.id, import)
|
||||||
update_import_points_count(import)
|
update_import_points_count(import)
|
||||||
|
User.reset_counters(user.id, :points)
|
||||||
rescue StandardError => e
|
rescue StandardError => e
|
||||||
import.update!(status: :failed)
|
import.update!(status: :failed)
|
||||||
broadcast_status_update
|
broadcast_status_update
|
||||||
|
|
|
||||||
|
|
@ -5,12 +5,8 @@ class AddPointsCountToUsers < ActiveRecord::Migration[8.0]
|
||||||
# Initialize counter cache for existing users using background job
|
# Initialize counter cache for existing users using background job
|
||||||
reversible do |dir|
|
reversible do |dir|
|
||||||
dir.up do
|
dir.up do
|
||||||
# Enqueue job to prefill counter cache in background
|
|
||||||
# This prevents the migration from blocking on large datasets
|
|
||||||
say_with_time "Enqueueing job to prefill points counter cache" do
|
|
||||||
DataMigrations::PrefillPointsCounterCacheJob.perform_later
|
DataMigrations::PrefillPointsCounterCacheJob.perform_later
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
|
||||||
1
db/schema.rb
generated
1
db/schema.rb
generated
|
|
@ -10,7 +10,6 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
|
|
||||||
ActiveRecord::Schema[8.0].define(version: 2025_08_23_125940) do
|
ActiveRecord::Schema[8.0].define(version: 2025_08_23_125940) do
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "pg_catalog.plpgsql"
|
enable_extension "pg_catalog.plpgsql"
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,15 @@ RSpec.describe Imports::Create do
|
||||||
expect(import.reload.source).to eq('owntracks')
|
expect(import.reload.source).to eq('owntracks')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'resets points counter cache' do
|
||||||
|
allow(User).to receive(:reset_counters)
|
||||||
|
|
||||||
|
service.call
|
||||||
|
|
||||||
|
expect(User).to have_received(:reset_counters).with(user.id, :points)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
context 'when import succeeds' do
|
context 'when import succeeds' do
|
||||||
it 'sets status to completed' do
|
it 'sets status to completed' do
|
||||||
service.call
|
service.call
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue