Bust cache after commit, rather than after save (#13455)

There's a (tiny) race condition where if an enclosing transaction
has not yet been committed when a user is created, and a sidekiq
worker begins find(:id) and fails, that the job is enqueued, started,
and skipped.

This changes the after_save hook on User to after_commit, ensuring the
user's assigned id is visible to other processes.
This commit is contained in:
Daniel Uber 2021-04-21 10:54:19 -05:00 committed by GitHub
parent 8016a33dd2
commit a615105653
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -271,10 +271,10 @@ class User < ApplicationRecord
# NOTE: @citizen428 Temporary while migrating to generalized profiles
after_save { |user| user.profile&.save if user.profile&.changed? }
after_save :bust_cache
after_save :subscribe_to_mailchimp_newsletter
after_create_commit :send_welcome_notification
after_commit :bust_cache
after_commit :index_to_elasticsearch, on: %i[create update]
after_commit :sync_related_elasticsearch_docs, on: %i[create update]
after_commit :remove_from_elasticsearch, on: [:destroy]