mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-04 13:06:50 +00:00
Add more performance metrics
This commit is contained in:
parent
b9cbd241de
commit
ca882dba73
7 changed files with 79 additions and 36 deletions
|
|
@ -4,6 +4,8 @@ using System.Linq;
|
|||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using App.Metrics;
|
||||
|
||||
using DSharpPlus;
|
||||
using DSharpPlus.Entities;
|
||||
|
||||
|
|
@ -18,11 +20,13 @@ namespace PluralKit.Bot
|
|||
private DiscordShardedClient _client;
|
||||
private ConcurrentDictionary<ulong, Lazy<Task<DiscordWebhook>>> _webhooks;
|
||||
|
||||
private IMetrics _metrics;
|
||||
private ILogger _logger;
|
||||
|
||||
public WebhookCacheService(DiscordShardedClient client, ILogger logger)
|
||||
public WebhookCacheService(DiscordShardedClient client, ILogger logger, IMetrics metrics)
|
||||
{
|
||||
_client = client;
|
||||
_metrics = metrics;
|
||||
_logger = logger.ForContext<WebhookCacheService>();
|
||||
_webhooks = new ConcurrentDictionary<ulong, Lazy<Task<DiscordWebhook>>>();
|
||||
}
|
||||
|
|
@ -78,6 +82,7 @@ namespace PluralKit.Bot
|
|||
private async Task<DiscordWebhook> GetOrCreateWebhook(DiscordChannel channel)
|
||||
{
|
||||
_logger.Debug("Webhook for channel {Channel} not found in cache, trying to fetch", channel.Id);
|
||||
_metrics.Measure.Meter.Mark(BotMetrics.WebhookCacheMisses);
|
||||
return await FindExistingWebhook(channel) ?? await DoCreateWebhook(channel);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue