Skip to content
This repository has been archived by the owner on Jan 3, 2025. It is now read-only.

Commit

Permalink
move invalidating Redis to after_create and after_update hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
FinnIckler committed Sep 23, 2024
1 parent a38da68 commit 22b0ae0
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
3 changes: 0 additions & 3 deletions app/controllers/registration_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion app/jobs/registration_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions app/models/registration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
4 changes: 4 additions & 0 deletions lib/redis_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 22b0ae0

Please sign in to comment.