Created
July 4, 2024 14:30
-
-
Save swanson/c13f4fcfed78e52d0e71071f3dfd3d03 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def record_event!(action, user: Current.user, record: nil, extra: {}, throttle: false, throttle_amount: 5.minutes) | |
if throttle.present? | |
existing = events.find_by(action: action, record: record, user: user, occurred_at: throttle_amount.ago..) | |
return existing if existing&.touch(:occurred_at) | |
end | |
events.create!(action: action, record: record, user: user, extra: extra) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment