Fix IPIntel causing frequent errors with the cleanup job. (#34428)

Co-authored-by: Pieter-Jan Briers <pieterjan.briers@gmail.com>
This commit is contained in:
Myra
2025-01-14 21:38:26 +01:00
committed by GitHub
parent 8e7f440243
commit 13edd308bf
3 changed files with 18 additions and 6 deletions

View File

@@ -94,9 +94,16 @@ namespace Content.Server.Connection
time = newTime;
}
public void Update()
public async void Update()
{
_ipintel.Update();
try
{
await _ipintel.Update();
}
catch (Exception e)
{
_sawmill.Error("IPIntel update failed:" + e);
}
}
/*

View File

@@ -38,6 +38,7 @@ public sealed class IPIntel
_sawmill = logManager.GetSawmill("ipintel");
cfg.OnValueChanged(CCVars.GameIPIntelEmail, b => _contactEmail = b, true);
cfg.OnValueChanged(CCVars.GameIPIntelEnabled, b => _enabled = b, true);
cfg.OnValueChanged(CCVars.GameIPIntelRejectUnknown, b => _rejectUnknown = b, true);
cfg.OnValueChanged(CCVars.GameIPIntelRejectBad, b => _rejectBad = b, true);
cfg.OnValueChanged(CCVars.GameIPIntelRejectRateLimited, b => _rejectLimited = b, true);
@@ -74,6 +75,7 @@ public sealed class IPIntel
// CCVars
private string? _contactEmail;
private bool _enabled;
private bool _rejectUnknown;
private bool _rejectBad;
private bool _rejectLimited;
@@ -273,12 +275,12 @@ public sealed class IPIntel
return _rejectBad ? (true, Loc.GetString("ipintel-suspicious")) : (false, string.Empty);
}
public void Update()
public async Task Update()
{
if (_gameTiming.RealTime >= _nextClean)
if (_enabled && _gameTiming.RealTime >= _nextClean)
{
_nextClean = _gameTiming.RealTime + TimeSpan.FromMinutes(_cleanupMins);
_db.CleanIPIntelCache(_cacheDays);
await _db.CleanIPIntelCache(_cacheDays);
}
}

View File

@@ -1774,8 +1774,11 @@ INSERT INTO player_round (players_id, rounds_id) VALUES ({players[player]}, {id}
{
await using var db = await GetDb();
// Calculating this here cause otherwise sqlite whines.
var cutoffTime = DateTime.UtcNow.Subtract(range);
await db.DbContext.IPIntelCache
.Where(w => DateTime.UtcNow - w.Time >= range)
.Where(w => w.Time <= cutoffTime)
.ExecuteDeleteAsync();
await db.DbContext.SaveChangesAsync();