mirror of
https://github.com/Retrospring/retrospring.git
synced 2024-11-20 16:19:52 +01:00
Merge pull request #1482 from Retrospring/task/cache-ban-state
Cache ban state
This commit is contained in:
commit
3c7940ae1b
1 changed files with 8 additions and 4 deletions
|
@ -6,14 +6,17 @@ module User::BanMethods
|
||||||
end
|
end
|
||||||
|
|
||||||
def banned?
|
def banned?
|
||||||
|
Rails.cache.fetch("#{cache_key}/banned") do
|
||||||
bans.current.count.positive?
|
bans.current.count.positive?
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def unban
|
def unban
|
||||||
bans.current.update(
|
bans.current.update(
|
||||||
# -1s to account for flakyness with timings in tests
|
# -1s to account for flakyness with timings in tests
|
||||||
expires_at: DateTime.now.utc - 1.second
|
expires_at: DateTime.now.utc - 1.second,
|
||||||
)
|
)
|
||||||
|
Rails.cache.delete("#{cache_key}/banned")
|
||||||
end
|
end
|
||||||
|
|
||||||
# Bans a user.
|
# Bans a user.
|
||||||
|
@ -24,8 +27,9 @@ module User::BanMethods
|
||||||
::UserBan.create!(
|
::UserBan.create!(
|
||||||
user: self,
|
user: self,
|
||||||
expires_at: expiry,
|
expires_at: expiry,
|
||||||
banned_by: banned_by,
|
banned_by:,
|
||||||
reason: reason
|
reason:,
|
||||||
)
|
)
|
||||||
|
Rails.cache.delete("#{cache_key}/banned")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue