diff options
author | Starfall <us@starfall.systems> | 2021-02-08 15:01:01 -0600 |
---|---|---|
committer | Starfall <us@starfall.systems> | 2021-02-08 15:01:01 -0600 |
commit | 3693000bf6a94219e3cc4a29a6cb4ac51b78cf2a (patch) | |
tree | 5e0a9757d315ca3aafe4db1ce10d3c4d84769408 /app/models/account_migration.rb | |
parent | ab4c09a7041050e4aa4b8333484e311f26a36b4a (diff) | |
parent | 4ed9576cd28abc033a094fed6babe9825014f1af (diff) |
Merge remote-tracking branch 'glitchsoc/main' into main
Diffstat (limited to 'app/models/account_migration.rb')
-rw-r--r-- | app/models/account_migration.rb | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/app/models/account_migration.rb b/app/models/account_migration.rb index 4fae98ed7..ded32c9c6 100644 --- a/app/models/account_migration.rb +++ b/app/models/account_migration.rb @@ -14,6 +14,8 @@ # class AccountMigration < ApplicationRecord + include Redisable + COOLDOWN_PERIOD = 30.days.freeze belongs_to :account @@ -39,7 +41,13 @@ class AccountMigration < ApplicationRecord return false unless errors.empty? - save + RedisLock.acquire(lock_options) do |lock| + if lock.acquired? + save + else + raise Mastodon::RaceConditionError + end + end end def cooldown_at @@ -75,4 +83,8 @@ class AccountMigration < ApplicationRecord def validate_migration_cooldown errors.add(:base, I18n.t('migrations.errors.on_cooldown')) if account.migrations.within_cooldown.exists? end + + def lock_options + { redis: redis, key: "account_migration:#{account.id}" } + end end |