🐛 Trying to fix check in locking

This commit is contained in:
2025-05-25 12:26:12 +08:00
parent 68399dd371
commit c562f52538
2 changed files with 17 additions and 9 deletions

View File

@ -142,7 +142,8 @@ public class AccountEventService(
public async Task<CheckInResult> CheckInDaily(Account user)
{
var lockKey = $"{CheckInLockKey}{user.Id}";
var lk = await cache.AcquireLockAsync(lockKey, TimeSpan.FromMinutes(10), TimeSpan.Zero);
await using var lk = await cache.AcquireLockAsync(lockKey, TimeSpan.FromMinutes(10), TimeSpan.Zero);
if (lk is null) throw new InvalidOperationException("Check-in was in progress.");
var cultureInfo = new CultureInfo(user.Language, false);
@ -212,7 +213,7 @@ public class AccountEventService(
ActivityVisibility.Friends
);
await lk.ReleaseAsync();
// The lock will be automatically released by the await using statement
return result;
}