diff --git a/app/controllers/registration_controller.rb b/app/controllers/registration_controller.rb index f6b19e11..82d3fc06 100644 --- a/app/controllers/registration_controller.rb +++ b/app/controllers/registration_controller.rb @@ -138,9 +138,6 @@ def process_update(update_request) EmailApi.send_update_email(@competition_id, user_id, status, @current_user) end - # Invalidate cache - Rails.cache.delete("#{user_id}-registrations-by-user") - { user_id: updated_registration['user_id'], guests: updated_registration.guests, diff --git a/app/jobs/registration_processor.rb b/app/jobs/registration_processor.rb index 8bb9b8b1..ad92ae27 100644 --- a/app/jobs/registration_processor.rb +++ b/app/jobs/registration_processor.rb @@ -17,7 +17,6 @@ def perform(message) message[:created_at], side_effects) end - Rails.cache.delete("#{message[:user_id]}-registrations-by-user") side_effects.run(:after_processing) Metrics.increment('registrations_processed') end diff --git a/app/models/registration.rb b/app/models/registration.rb index ddfbca22..054a86e9 100644 --- a/app/models/registration.rb +++ b/app/models/registration.rb @@ -14,6 +14,10 @@ class Registration # Pre-validations before_validation :set_competing_status + # Hooks + after_create :delete_user_registration_from_redis + after_update :delete_user_registration_from_redis + # Validations validate :competing_status_consistency @@ -216,4 +220,8 @@ def waiting_list_status_changed?(update_params) states_are_different = competing_status != update_params[:status] lane_state_present && states_are_different end + + def delete_user_registration_from_redis + RedisHelper.delete_user_registrations(user_id) + end end diff --git a/lib/redis_helper.rb b/lib/redis_helper.rb index b060c986..153fed18 100644 --- a/lib/redis_helper.rb +++ b/lib/redis_helper.rb @@ -9,6 +9,10 @@ def self.increment_or_initialize(key, &) end end + def self.delete_user_registrations(user_id) + Rails.cache.delete("#{user_id}-registrations-by-user") + end + def self.decrement_or_initialize(key, &) if Rails.cache.exist?(key) Rails.cache.decrement(key)