mirror of
https://github.com/NoiTheCat/BirthdayBot.git
synced 2024-11-23 17:04:12 +00:00
Fix user last_seen not updating properly
Also now displays basic statistics on how many records are updated in each pass whenever StaleDataCleaner does its work.
This commit is contained in:
parent
e3a86dd6dc
commit
b6c201d5a5
2 changed files with 8 additions and 6 deletions
|
@ -19,9 +19,6 @@ namespace BirthdayBot.BackgroundServices
|
|||
var updateList = new Dictionary<ulong, List<ulong>>();
|
||||
foreach (var gi in BotInstance.GuildCache)
|
||||
{
|
||||
var existingUsers = new List<ulong>();
|
||||
updateList[gi.Key] = existingUsers;
|
||||
|
||||
var guild = BotInstance.DiscordClient.GetGuild(gi.Key);
|
||||
if (guild == null) continue; // Have cache without being in guild. Unlikely, but...
|
||||
|
||||
|
@ -29,6 +26,7 @@ namespace BirthdayBot.BackgroundServices
|
|||
var cachedUserIds = from cu in gi.Value.Users select cu.UserId;
|
||||
var guildUserIds = from gu in guild.Users select gu.Id;
|
||||
var existingCachedIds = cachedUserIds.Intersect(guildUserIds);
|
||||
updateList[gi.Key] = new List<ulong>(existingCachedIds);
|
||||
}
|
||||
|
||||
using (var db = await BotInstance.Config.DatabaseSettings.OpenConnectionAsync())
|
||||
|
@ -47,6 +45,9 @@ namespace BirthdayBot.BackgroundServices
|
|||
var pUpdateGU_u = cUpdateGuildUser.Parameters.Add("@Uid", NpgsqlDbType.Bigint);
|
||||
cUpdateGuildUser.Prepare();
|
||||
|
||||
int updatedGuilds = 0;
|
||||
int updatedUsers = 0;
|
||||
|
||||
// Do actual updates
|
||||
foreach (var item in updateList)
|
||||
{
|
||||
|
@ -54,15 +55,16 @@ namespace BirthdayBot.BackgroundServices
|
|||
var userlist = item.Value;
|
||||
|
||||
pUpdateG.Value = (long)guild;
|
||||
cUpdateGuild.ExecuteNonQuery();
|
||||
updatedGuilds += cUpdateGuild.ExecuteNonQuery();
|
||||
|
||||
pUpdateGU_g.Value = (long)guild;
|
||||
foreach (var userid in userlist)
|
||||
{
|
||||
pUpdateGU_u.Value = (long)userid;
|
||||
cUpdateGuildUser.ExecuteNonQuery();
|
||||
updatedUsers += cUpdateGuildUser.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
Log($"Updated last-seen records: {updatedGuilds} guilds, {updatedUsers} users");
|
||||
|
||||
// Delete all old values - expects referencing tables to have 'on delete cascade'
|
||||
using (var t = db.BeginTransaction())
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<Version>2.2.0</Version>
|
||||
<Version>2.2.1</Version>
|
||||
<PackageId>BirthdayBot</PackageId>
|
||||
<Authors>NoiTheCat</Authors>
|
||||
<Product>BirthdayBot</Product>
|
||||
|
|
Loading…
Reference in a new issue