mirror of
https://github.com/NoiTheCat/BirthdayBot.git
synced 2024-11-21 13:54:36 +00:00
Fix StaleDataCleaner not working
This commit is contained in:
parent
99786a7b70
commit
f839890b73
2 changed files with 11 additions and 15 deletions
|
@ -11,22 +11,17 @@ namespace BirthdayBot
|
|||
/// </summary>
|
||||
class BackgroundServiceRunner
|
||||
{
|
||||
// Amount of idle time between each round of task execution, in seconds.
|
||||
#if DEBUG
|
||||
// Amount of idle time between each round of task execution, in seconds.
|
||||
const int Interval = 10;
|
||||
|
||||
// Amount of time between start and first round of processing, in seconds.
|
||||
const int StartDelay = 15;
|
||||
#else
|
||||
#if !DEBUG
|
||||
// Amount of idle time between each round of task execution, in seconds.
|
||||
const int Interval = 8 * 60;
|
||||
|
||||
// Amount of time between start and first round of processing, in seconds.
|
||||
const int StartDelay = 60;
|
||||
#else
|
||||
const int Interval = 10;
|
||||
const int StartDelay = 15;
|
||||
#endif
|
||||
|
||||
|
||||
const string LogName = nameof(BackgroundServiceRunner);
|
||||
|
||||
private List<BackgroundService> _workers;
|
||||
|
@ -43,7 +38,8 @@ namespace BirthdayBot
|
|||
{
|
||||
{new GuildStatistics(instance)},
|
||||
{new Heartbeat(instance)},
|
||||
{BirthdayUpdater}
|
||||
{BirthdayUpdater},
|
||||
{new StaleDataCleaner(instance)}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ namespace BirthdayBot.BackgroundServices
|
|||
cUpdateGuildUser.CommandText = $"update {GuildUserSettings.BackingTable} set last_seen = now() "
|
||||
+ "where guild_id = @Gid and user_id = @Uid";
|
||||
var pUpdateGU_g = cUpdateGuildUser.Parameters.Add("@Gid", NpgsqlDbType.Bigint);
|
||||
var pUpdateGU_u = cUpdateGuild.Parameters.Add("@Uid", NpgsqlDbType.Bigint);
|
||||
var pUpdateGU_u = cUpdateGuildUser.Parameters.Add("@Uid", NpgsqlDbType.Bigint);
|
||||
cUpdateGuildUser.Prepare();
|
||||
|
||||
// Do actual updates
|
||||
|
@ -67,20 +67,20 @@ namespace BirthdayBot.BackgroundServices
|
|||
// Delete all old values - expects referencing tables to have 'on delete cascade'
|
||||
using (var t = db.BeginTransaction())
|
||||
{
|
||||
int staleGuilds, staleUsers;
|
||||
using (var c = db.CreateCommand())
|
||||
{
|
||||
// Delete data for guilds not seen in 4 weeks
|
||||
c.CommandText = $"delete from {GuildStateInformation.BackingTable} where (now() - interval '28 days') > last_seen";
|
||||
var r = c.ExecuteNonQuery();
|
||||
if (r != 0) Log($"Removed {r} stale guild(s).");
|
||||
staleGuilds = c.ExecuteNonQuery();
|
||||
}
|
||||
using (var c = db.CreateCommand())
|
||||
{
|
||||
// Delete data for users not seen in 8 weeks
|
||||
c.CommandText = $"delete from {GuildUserSettings.BackingTable} where (now() - interval '56 days') > last_seen";
|
||||
var r = c.ExecuteNonQuery();
|
||||
if (r != 0) Log($"Removed {r} stale user(s).");
|
||||
staleUsers = c.ExecuteNonQuery();
|
||||
}
|
||||
Log($"Will remove {staleGuilds} guilds, {staleUsers} users.");
|
||||
t.Commit();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue