From b13659817defcc355811211f3ca6fe18064a7852 Mon Sep 17 00:00:00 2001 From: spiral Date: Sun, 15 Jan 2023 17:34:40 +0000 Subject: [PATCH] fix(bot): try fetching messages from database before deleting --- .../Database/Repository/ModelRepository.Message.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/PluralKit.Core/Database/Repository/ModelRepository.Message.cs b/PluralKit.Core/Database/Repository/ModelRepository.Message.cs index 589e9934..b58b43c0 100644 --- a/PluralKit.Core/Database/Repository/ModelRepository.Message.cs +++ b/PluralKit.Core/Database/Repository/ModelRepository.Message.cs @@ -44,8 +44,8 @@ public partial class ModelRepository public async Task DeleteMessage(ulong id) { - _logger.Warning("not deleting message from database because of database issues", id); - return; + if ((await GetMessage(id)) == null) + return; var query = new Query("messages").AsDelete().Where("mid", id); var rowCount = await _db.ExecuteQuery(query, messages: true); @@ -55,12 +55,13 @@ public partial class ModelRepository public async Task DeleteMessagesBulk(IReadOnlyCollection ids) { - _logger.Warning("not bulk deleting {count} messages from database because of database issues", ids.Count, ids); - return; + var q = new Query("messages").Select("mid").WhereIn("mid", ids.Select(id => (long)id).ToArray()); + var realIds = await _db.Query(q); + if (realIds.Count() == 0) return; // Npgsql doesn't support ulongs in general - we hacked around it for plain ulongs but tbh not worth it for collections of ulong // Hence we map them to single longs, which *are* supported (this is ok since they're Technically (tm) stored as signed longs in the db anyway) - var query = new Query("messages").AsDelete().WhereIn("mid", ids.Select(id => (long)id).ToArray()); + var query = new Query("messages").AsDelete().WhereIn("mid", realIds); var rowCount = await _db.ExecuteQuery(query, messages: true); if (rowCount > 0) _logger.Information("Bulk deleted messages ({FoundCount} found) from database: {MessageIds}", rowCount,