Skip to content

Instantly share code, notes, and snippets.

@swanson
Created July 4, 2024 14:30
Show Gist options
  • Save swanson/c13f4fcfed78e52d0e71071f3dfd3d03 to your computer and use it in GitHub Desktop.
Save swanson/c13f4fcfed78e52d0e71071f3dfd3d03 to your computer and use it in GitHub Desktop.
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