Merge branch 'main' into feature/public-reminder
This commit is contained in:
@@ -19,7 +19,7 @@ namespace PluralKit.Core
|
||||
internal class Database: IDatabase
|
||||
{
|
||||
private const string RootPath = "PluralKit.Core.Database"; // "resource path" root for SQL files
|
||||
private const int TargetSchemaVersion = 10;
|
||||
private const int TargetSchemaVersion = 11;
|
||||
|
||||
private readonly CoreConfig _config;
|
||||
private readonly ILogger _logger;
|
||||
|
17
PluralKit.Core/Database/Migrations/11.sql
Normal file
17
PluralKit.Core/Database/Migrations/11.sql
Normal file
@@ -0,0 +1,17 @@
|
||||
-- SCHEMA VERSION 11: (insert date) --
|
||||
-- Create command message table --
|
||||
|
||||
create table command_message
|
||||
(
|
||||
message_id bigint primary key,
|
||||
author_id bigint not null,
|
||||
timestamp timestamp not null default now()
|
||||
);
|
||||
|
||||
create function cleanup_command_message() returns void as $$
|
||||
begin
|
||||
delete from command_message where timestamp < now() - interval '2 hours';
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
update info set schema_version = 11;
|
@@ -0,0 +1,24 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Dapper;
|
||||
|
||||
namespace PluralKit.Core
|
||||
{
|
||||
public partial class ModelRepository
|
||||
{
|
||||
public Task SaveCommandMessage(IPKConnection conn, ulong message_id, ulong author_id) =>
|
||||
conn.QueryAsync("insert into command_message (message_id, author_id) values (@Message, @Author)",
|
||||
new {Message = message_id, Author = author_id });
|
||||
|
||||
public Task<CommandMessage> GetCommandMessage(IPKConnection conn, ulong message_id) =>
|
||||
conn.QuerySingleOrDefaultAsync<CommandMessage>("select message_id, author_id from command_message where message_id = @Message",
|
||||
new {Message = message_id});
|
||||
}
|
||||
|
||||
public class CommandMessage
|
||||
{
|
||||
public ulong author_id { get; set; }
|
||||
}
|
||||
}
|
@@ -119,7 +119,9 @@ namespace PluralKit.Core
|
||||
system = result.System = await _repo.CreateSystem(conn, data.Name);
|
||||
await _repo.AddAccount(conn, system.Id, accountId);
|
||||
}
|
||||
|
||||
|
||||
var memberLimit = system.MemberLimitOverride ?? Limits.MaxMemberCount;
|
||||
|
||||
// Apply system info
|
||||
var patch = new SystemPatch {Name = data.Name};
|
||||
if (data.Description != null) patch.Description = data.Description;
|
||||
@@ -135,10 +137,10 @@ namespace PluralKit.Core
|
||||
// If creating the unmatched members would put us over the member limit, abort before creating any members
|
||||
var memberCountBefore = await _repo.GetSystemMemberCount(conn, system.Id);
|
||||
var membersToAdd = data.Members.Count(m => imp.IsNewMember(m.Id, m.Name));
|
||||
if (memberCountBefore + membersToAdd > Limits.MaxMemberCount)
|
||||
if (memberCountBefore + membersToAdd > memberLimit)
|
||||
{
|
||||
result.Success = false;
|
||||
result.Message = $"Import would exceed the maximum number of members ({Limits.MaxMemberCount}).";
|
||||
result.Message = $"Import would exceed the maximum number of members ({memberLimit}).";
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -204,7 +206,8 @@ namespace PluralKit.Core
|
||||
[JsonIgnore] public bool Valid =>
|
||||
TimeZoneValid &&
|
||||
Members != null &&
|
||||
Members.Count <= Limits.MaxMemberCount &&
|
||||
// no need to check this here, it is checked later as part of the import
|
||||
// Members.Count <= Limits.MaxMemberCount &&
|
||||
Members.All(m => m.Valid) &&
|
||||
Switches != null &&
|
||||
Switches.Count < 10000 &&
|
||||
@@ -361,4 +364,4 @@ namespace PluralKit.Core
|
||||
|
||||
[JsonIgnore] public bool Valid => true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -6,7 +6,7 @@ namespace PluralKit.Core {
|
||||
public static readonly int MaxSystemNameLength = 100;
|
||||
public static readonly int MaxSystemTagLength = MaxProxyNameLength - 1;
|
||||
public static readonly int MaxMemberCount = 1000;
|
||||
public static readonly int MaxMembersWarnThreshold = MaxMemberCount - 50;
|
||||
public static int MaxMembersWarnThreshold (int memberLimit) => memberLimit - 50;
|
||||
public static readonly int MaxGroupCount = 250;
|
||||
public static readonly int MaxDescriptionLength = 1000;
|
||||
public static readonly int MaxMemberNameLength = 100; // Fair bit larger than MaxProxyNameLength for bookkeeping
|
||||
|
Reference in New Issue
Block a user