Add more performance metrics

This commit is contained in:
Ske
2020-06-14 22:19:12 +02:00
parent b9cbd241de
commit ca882dba73
7 changed files with 79 additions and 36 deletions

View File

@@ -55,8 +55,13 @@ namespace PluralKit.Bot
_metrics.Measure.Meter.Mark(BotMetrics.MessagesReceived);
_lastMessageCache.AddMessage(evt.Channel.Id, evt.Message.Id);
// Get message context from DB (tracking w/ metrics)
MessageContext ctx;
await using (var conn = await _db.Obtain())
using (_metrics.Measure.Timer.Time(BotMetrics.MessageContextQueryTime))
ctx = await conn.QueryMessageContext(evt.Author.Id, evt.Channel.GuildId, evt.Channel.Id);
// Try each handler until we find one that succeeds
var ctx = await _db.Execute(c => c.QueryMessageContext(evt.Author.Id, evt.Channel.GuildId, evt.Channel.Id));
var _ = await TryHandleLogClean(evt, ctx) ||
await TryHandleCommand(evt, ctx) ||
await TryHandleProxy(evt, ctx);

View File

@@ -1,5 +1,7 @@
using System.Threading.Tasks;
using App.Metrics;
using DSharpPlus.EventArgs;
using PluralKit.Core;
@@ -12,12 +14,14 @@ namespace PluralKit.Bot
private readonly LastMessageCacheService _lastMessageCache;
private readonly ProxyService _proxy;
private readonly IDatabase _db;
private readonly IMetrics _metrics;
public MessageEdited(LastMessageCacheService lastMessageCache, ProxyService proxy, IDatabase db)
public MessageEdited(LastMessageCacheService lastMessageCache, ProxyService proxy, IDatabase db, IMetrics metrics)
{
_lastMessageCache = lastMessageCache;
_proxy = proxy;
_db = db;
_metrics = metrics;
}
public async Task Handle(MessageUpdateEventArgs evt)
@@ -29,7 +33,10 @@ namespace PluralKit.Bot
if (_lastMessageCache.GetLastMessage(evt.Channel.Id) != evt.Message.Id) return;
// Just run the normal message handling code, with a flag to disable autoproxying
var ctx = await _db.Execute(c => c.QueryMessageContext(evt.Author.Id, evt.Channel.GuildId, evt.Channel.Id));
MessageContext ctx;
await using (var conn = await _db.Obtain())
using (_metrics.Measure.Timer.Time(BotMetrics.MessageContextQueryTime))
ctx = await conn.QueryMessageContext(evt.Author.Id, evt.Channel.GuildId, evt.Channel.Id);
await _proxy.HandleIncomingMessage(evt.Message, ctx, allowAutoproxy: false);
}
}