mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 22:44:29 +01:00
Better timing measurement during invoice creation
This commit is contained in:
@@ -200,9 +200,10 @@ namespace BTCPayServer.Controllers
|
|||||||
entity.InternalTags.Add(AppService.GetAppInternalTag(app.Id));
|
entity.InternalTags.Add(AppService.GetAppInternalTag(app.Id));
|
||||||
}
|
}
|
||||||
|
|
||||||
logs.Write($"Saving invoice...");
|
using (logs.Measure("Saving invoice"))
|
||||||
entity = await _InvoiceRepository.CreateInvoiceAsync(store.Id, entity, _NetworkProvider);
|
{
|
||||||
logs.Write($"Invoice saved!");
|
entity = await _InvoiceRepository.CreateInvoiceAsync(store.Id, entity, _NetworkProvider);
|
||||||
|
}
|
||||||
_ = Task.Run(async () =>
|
_ = Task.Run(async () =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -258,10 +259,11 @@ namespace BTCPayServer.Controllers
|
|||||||
paymentMethod.Rate = rate.BidAsk.Bid;
|
paymentMethod.Rate = rate.BidAsk.Bid;
|
||||||
paymentMethod.PreferOnion = this.Request.IsOnion();
|
paymentMethod.PreferOnion = this.Request.IsOnion();
|
||||||
|
|
||||||
logs.Write($"{logPrefix} Creating payment method details...");
|
using (logs.Measure($"{logPrefix} Payment method details creation"))
|
||||||
var paymentDetails = await handler.CreatePaymentMethodDetails(supportedPaymentMethod, paymentMethod, store, network, preparePayment);
|
{
|
||||||
logs.Write($"{logPrefix} Payment method details created...");
|
var paymentDetails = await handler.CreatePaymentMethodDetails(supportedPaymentMethod, paymentMethod, store, network, preparePayment);
|
||||||
paymentMethod.SetPaymentMethodDetails(paymentDetails);
|
paymentMethod.SetPaymentMethodDetails(paymentDetails);
|
||||||
|
}
|
||||||
|
|
||||||
Func<Money, Money, bool> compare = null;
|
Func<Money, Money, bool> compare = null;
|
||||||
CurrencyValue limitValue = null;
|
CurrencyValue limitValue = null;
|
||||||
|
|||||||
@@ -33,5 +33,35 @@ namespace BTCPayServer.Logging
|
|||||||
return _InvoiceLogs.ToList();
|
return _InvoiceLogs.ToList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal IDisposable Measure(string logs)
|
||||||
|
{
|
||||||
|
return new Mesuring(this, logs);
|
||||||
|
}
|
||||||
|
|
||||||
|
class Mesuring : IDisposable
|
||||||
|
{
|
||||||
|
private readonly InvoiceLogs _logs;
|
||||||
|
private readonly string _msg;
|
||||||
|
private readonly DateTimeOffset _Before;
|
||||||
|
public Mesuring(InvoiceLogs logs, string msg)
|
||||||
|
{
|
||||||
|
_logs = logs;
|
||||||
|
_msg = msg;
|
||||||
|
_Before = DateTimeOffset.UtcNow;
|
||||||
|
}
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
var timespan = DateTimeOffset.UtcNow - _Before;
|
||||||
|
if (timespan.TotalSeconds >= 1.0)
|
||||||
|
{
|
||||||
|
_logs.Write($"{_msg} took {(int)timespan.TotalSeconds} seconds");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logs.Write($"{_msg} took {(int)timespan.TotalMilliseconds} milliseconds");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user