mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-09 07:17:56 +00:00
feat: block running commands / proxying when system is being deleted
Large systems take way too long to delete, which causes any insert for that system to block a connection, which exhausts the connection pool
This commit is contained in:
parent
375e650c9e
commit
be89f907a0
7 changed files with 31 additions and 3 deletions
|
|
@ -10,6 +10,11 @@ namespace PluralKit.Core;
|
|||
public class MessageContext
|
||||
{
|
||||
public SystemId? SystemId { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether a system is being deleted (no actions should be taken, or commands ran)
|
||||
/// </summary>
|
||||
public bool IsDeleting { get; }
|
||||
public ulong? LogChannel { get; }
|
||||
public bool InBlacklist { get; }
|
||||
public bool InLogBlacklist { get; }
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
create function message_context(account_id bigint, guild_id bigint, channel_id bigint)
|
||||
returns table (
|
||||
system_id int,
|
||||
is_deleting bool,
|
||||
log_channel bigint,
|
||||
in_blacklist bool,
|
||||
in_log_blacklist bool,
|
||||
|
|
@ -27,6 +28,7 @@ as $$
|
|||
guild as (select * from servers where id = guild_id)
|
||||
select
|
||||
system.id as system_id,
|
||||
system.is_deleting,
|
||||
guild.log_channel,
|
||||
(channel_id = any(guild.blacklist)) as in_blacklist,
|
||||
(channel_id = any(guild.log_blacklist)) as in_log_blacklist,
|
||||
|
|
|
|||
5
PluralKit.Core/Database/Migrations/29.sql
Normal file
5
PluralKit.Core/Database/Migrations/29.sql
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
-- schema version 29
|
||||
|
||||
alter table systems add column is_deleting bool default false;
|
||||
|
||||
update info set schema_version = 29;
|
||||
|
|
@ -142,10 +142,11 @@ public partial class ModelRepository
|
|||
});
|
||||
}
|
||||
|
||||
public Task DeleteSystem(SystemId id)
|
||||
public async Task DeleteSystem(SystemId id)
|
||||
{
|
||||
await _db.Execute(c => c.QueryAsync("update systems set is_deleting = true where id = @id", new { id = id }));
|
||||
var query = new Query("systems").AsDelete().Where("id", id);
|
||||
await _db.ExecuteQuery(query);
|
||||
_logger.Information("Deleted {SystemId}", id);
|
||||
return _db.ExecuteQuery(query);
|
||||
}
|
||||
}
|
||||
|
|
@ -9,7 +9,7 @@ namespace PluralKit.Core;
|
|||
internal class DatabaseMigrator
|
||||
{
|
||||
private const string RootPath = "PluralKit.Core.Database"; // "resource path" root for SQL files
|
||||
private const int TargetSchemaVersion = 28;
|
||||
private const int TargetSchemaVersion = 29;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public DatabaseMigrator(ILogger logger)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue