fix(bot): add callback to update message count after proxying
also re-add -with-last-message flag :D
This commit is contained in:
6
PluralKit.Core/Database/Migrations/32.sql
Normal file
6
PluralKit.Core/Database/Migrations/32.sql
Normal file
@@ -0,0 +1,6 @@
|
||||
-- database version 32
|
||||
-- re-add last message timestamp to members
|
||||
|
||||
alter table members add column last_message_timestamp timestamp;
|
||||
|
||||
update info set schema_version = 32;
|
@@ -97,4 +97,16 @@ public partial class ModelRepository
|
||||
new { member = id, account = userId }
|
||||
);
|
||||
}
|
||||
|
||||
public async Task UpdateMemberForSentMessage(MemberId id)
|
||||
{
|
||||
var query = new Query("members")
|
||||
.AsUpdate(new {
|
||||
last_message_timestamp = new UnsafeLiteral("now()"),
|
||||
message_count = new UnsafeLiteral("message_count + 1")
|
||||
})
|
||||
.Where("id", id);
|
||||
|
||||
await _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 = 31;
|
||||
private const int TargetSchemaVersion = 32;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public DatabaseMigrator(ILogger logger)
|
||||
|
@@ -6,7 +6,6 @@ namespace PluralKit.Core;
|
||||
// TODO: is inheritance here correct?
|
||||
public class ListedMember: PKMember
|
||||
{
|
||||
// public ulong? LastMessage { get; }
|
||||
public Instant? LastSwitchTime { get; }
|
||||
|
||||
public AnnualDate? AnnualBirthday =>
|
||||
|
@@ -9,10 +9,6 @@ from systems
|
||||
|
||||
create view member_list as
|
||||
select members.*,
|
||||
-- Find last message ID
|
||||
-- max(mid) does full table scan, order by/limit uses index (dunno why, but it works!)
|
||||
-- (select mid from messages where messages.member = members.id order by mid desc nulls last limit 1) as last_message,
|
||||
|
||||
-- Find last switch timestamp
|
||||
(
|
||||
select max(switches.timestamp)
|
||||
|
Reference in New Issue
Block a user