re-enable FixSameName (with database fix)

This commit is contained in:
spiral 2021-09-18 19:14:08 -04:00
parent 07b12f39b0
commit a09f819924
No known key found for this signature in database
GPG Key ID: A6059F0CA0E1BD31

View File

@ -247,17 +247,14 @@ namespace PluralKit.Bot
private async Task<string> FixSameName(ulong channelId, MessageContext ctx, ProxyMember member) private async Task<string> FixSameName(ulong channelId, MessageContext ctx, ProxyMember member)
{ {
// TODO: this function's disabled due to extra database pressure, find a way to do it without requiring an extra connection
var proxyName = member.ProxyName(ctx); var proxyName = member.ProxyName(ctx);
return proxyName;
var lastMessage = _lastMessage.GetLastMessage(channelId)?.Previous; var lastMessage = _lastMessage.GetLastMessage(channelId)?.Previous;
if (lastMessage == null) if (lastMessage == null)
// cache is out of date or channel is empty. // cache is out of date or channel is empty.
return proxyName; return proxyName;
await using var conn = await _db.Obtain(); var pkMessage = await _db.Execute(conn => _repo.GetMessage(conn, lastMessage.Id));
var pkMessage = await _repo.GetMessage(conn, lastMessage.Id);
if (lastMessage.AuthorUsername == proxyName) if (lastMessage.AuthorUsername == proxyName)
{ {