mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-08 23:07:54 +00:00
fix(bot): add callback to update message count after proxying
also re-add -with-last-message flag :D
This commit is contained in:
parent
8e0454a13b
commit
24db9f28c2
9 changed files with 32 additions and 17 deletions
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)
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@ public class PKMember
|
|||
public bool KeepProxy { get; private set; }
|
||||
public Instant Created { get; private set; }
|
||||
public int MessageCount { get; private set; }
|
||||
public Instant? LastMessageTimestamp { get; }
|
||||
public bool AllowAutoproxy { get; private set; }
|
||||
|
||||
public PrivacyLevel MemberVisibility { get; private set; }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue