Merge pull request #55 from NoiTheCat/fixes/retention-errors

Fix data retention bugs causing mass deletion of birthdays
This commit is contained in:
Noi 2024-04-28 00:10:12 -07:00 committed by GitHub
commit df09e4ab18
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 3 additions and 1 deletions

View file

@ -53,9 +53,11 @@ class DataRetention : BackgroundService {
// And let go of old data // And let go of old data
var staleGuildCount = await db.GuildConfigurations var staleGuildCount = await db.GuildConfigurations
.Where(g => localGuilds.Contains(g.GuildId))
.Where(g => now - TimeSpan.FromDays(StaleGuildThreshold) > g.LastSeen) .Where(g => now - TimeSpan.FromDays(StaleGuildThreshold) > g.LastSeen)
.ExecuteDeleteAsync(); .ExecuteDeleteAsync();
var staleUserCount = await db.UserEntries var staleUserCount = await db.UserEntries
.Where(gu => localGuilds.Contains(gu.GuildId))
.Where(gu => now - TimeSpan.FromDays(StaleUserThreashold) > gu.LastSeen) .Where(gu => now - TimeSpan.FromDays(StaleUserThreashold) > gu.LastSeen)
.ExecuteDeleteAsync(); .ExecuteDeleteAsync();

View file

@ -57,11 +57,11 @@ class ShardBackgroundWorker : IDisposable {
if (Instance.DiscordClient.ConnectionState != ConnectionState.Connected) continue; if (Instance.DiscordClient.ConnectionState != ConnectionState.Connected) continue;
// Execute tasks sequentially // Execute tasks sequentially
_tickCount++;
foreach (var service in _workers) { foreach (var service in _workers) {
CurrentExecutingService = service.GetType().Name; CurrentExecutingService = service.GetType().Name;
try { try {
if (_workerCanceller.IsCancellationRequested) break; if (_workerCanceller.IsCancellationRequested) break;
_tickCount++;
await service.OnTick(_tickCount, _workerCanceller.Token); await service.OnTick(_tickCount, _workerCanceller.Token);
} catch (Exception ex) when (ex is not } catch (Exception ex) when (ex is not
(TaskCanceledException or OperationCanceledException or ObjectDisposedException)) { (TaskCanceledException or OperationCanceledException or ObjectDisposedException)) {