Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a model hook around the lockable warden hook to reset attempts #5369

Merged
merged 1 commit into from
Apr 2, 2021

Conversation

carlosantoniodasilva
Copy link
Member

Resetting failed attempts after sign in happened inside a warden hook
specific for the lockable module, but that was hidden inside the hook
implementation and didn't allow any user customization.

One such customization needed for example is to direct these updates to
a write DB when using a multi-DB setup. With the logic hidden in the
warden hook this wasn't possible, now that it's exposed in a model
method much like trackable, we can override the model method to wrap it
in a connection switch block for example, point to a write DB, and
simply call super.

Closes #5310
Related to #5264 and #5133

Copy link

@geoffharcourt geoffharcourt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome. Thank you for taking this on, my apologies for not getting to it sooner! I think this change will help a lot of Rails 6 users with a replica database setup.

@carlosantoniodasilva carlosantoniodasilva force-pushed the ca-lockable-reset-attempts branch 2 times, most recently from d5c8fdb to 68da1d8 Compare March 22, 2021 21:52
@mhenrixon
Copy link

This looks great and not as complicated as I thought it would be. Kudos for tackling this problem! It is the one thing that prevents me from making full (and easy) use of the replica reads.

@geoffharcourt
Copy link

We've been using this change in production and haven't seen any exceptions from attempting to write to the read-only replica since applying it.

@carlosantoniodasilva carlosantoniodasilva force-pushed the ca-lockable-reset-attempts branch 2 times, most recently from ca6377c to dc36922 Compare April 2, 2021 18:42
Resetting failed attempts after sign in happened inside a warden hook
specific for the lockable module, but that was hidden inside the hook
implementation and didn't allow any user customization.

One such customization needed for example is to direct these updates to
a write DB when using a multi-DB setup. With the logic hidden in the
warden hook this wasn't possible, now that it's exposed in a model
method much like trackable, we can override the model method to wrap it
in a connection switch block for example, point to a write DB, and
simply call `super`.

Closes #5310
Related to #5264 and #5133
@carlosantoniodasilva carlosantoniodasilva force-pushed the ca-lockable-reset-attempts branch from dc36922 to a3ae35e Compare April 2, 2021 18:45
@carlosantoniodasilva carlosantoniodasilva marked this pull request as ready for review April 2, 2021 18:52
@carlosantoniodasilva carlosantoniodasilva merged commit 5d5636f into master Apr 2, 2021
@carlosantoniodasilva
Copy link
Member Author

Thanks @geoffharcourt @mhenrixon, this is now on master and will be on the next release, which I'm hoping to cut soon.

@paulspringett
Copy link

Hey @carlosantoniodasilva Please could I ask when you're planning on the next release to RubyGems? I've just come across this as we're looking for a fix to this issue with Rails 6.1 multi-database switching. Many thanks!

@carlosantoniodasilva
Copy link
Member Author

I just pushed v4.8 including this change, please give it a try and report back if you have any issues. Thanks.

@carlosantoniodasilva carlosantoniodasilva deleted the ca-lockable-reset-attempts branch April 29, 2021 11:54
@paulspringett
Copy link

@carlosantoniodasilva Thanks so much, really appreciate it 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants