mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-19 06:54:19 +01:00
Fix performance issue on dashboard for big wallets (#3694)
This commit is contained in:
@@ -8,16 +8,19 @@
|
|||||||
</header>
|
</header>
|
||||||
<div class="h3">@Model.PayoutsPending</div>
|
<div class="h3">@Model.PayoutsPending</div>
|
||||||
</div>
|
</div>
|
||||||
|
@if (Model.Transactions is not null)
|
||||||
|
{
|
||||||
<div class="store-number">
|
<div class="store-number">
|
||||||
<header>
|
<header>
|
||||||
<h6>TXs in the last @Model.TransactionDays days</h6>
|
<h6>TXs in the last @Model.TransactionDays days</h6>
|
||||||
@if (Model.Transactions > 0)
|
@if (Model.Transactions.Value > 0)
|
||||||
{
|
{
|
||||||
<a asp-controller="UIWallets" asp-action="WalletTransactions" asp-route-walletId="@Model.WalletId">View All</a>
|
<a asp-controller="UIWallets" asp-action="WalletTransactions" asp-route-walletId="@Model.WalletId">View All</a>
|
||||||
}
|
}
|
||||||
</header>
|
</header>
|
||||||
<div class="h3">@Model.Transactions</div>
|
<div class="h3">@Model.Transactions.Value</div>
|
||||||
</div>
|
</div>
|
||||||
|
}
|
||||||
<div class="store-number">
|
<div class="store-number">
|
||||||
<header>
|
<header>
|
||||||
<h6>Refunds Issued</h6>
|
<h6>Refunds Issued</h6>
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using Dapper;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using BTCPayServer.Client.Models;
|
using BTCPayServer.Client.Models;
|
||||||
using BTCPayServer.Components.StoreRecentTransactions;
|
using BTCPayServer.Components.StoreRecentTransactions;
|
||||||
using BTCPayServer.Data;
|
using BTCPayServer.Data;
|
||||||
|
using BTCPayServer.Services;
|
||||||
using BTCPayServer.Services.Stores;
|
using BTCPayServer.Services.Stores;
|
||||||
using BTCPayServer.Services.Wallets;
|
using BTCPayServer.Services.Wallets;
|
||||||
using Microsoft.AspNetCore.Identity;
|
using Microsoft.AspNetCore.Identity;
|
||||||
@@ -23,16 +25,19 @@ public class StoreNumbers : ViewComponent
|
|||||||
private readonly StoreRepository _storeRepo;
|
private readonly StoreRepository _storeRepo;
|
||||||
private readonly ApplicationDbContextFactory _dbContextFactory;
|
private readonly ApplicationDbContextFactory _dbContextFactory;
|
||||||
private readonly BTCPayWalletProvider _walletProvider;
|
private readonly BTCPayWalletProvider _walletProvider;
|
||||||
|
private readonly NBXplorerConnectionFactory _nbxConnectionFactory;
|
||||||
private readonly BTCPayNetworkProvider _networkProvider;
|
private readonly BTCPayNetworkProvider _networkProvider;
|
||||||
|
|
||||||
public StoreNumbers(
|
public StoreNumbers(
|
||||||
StoreRepository storeRepo,
|
StoreRepository storeRepo,
|
||||||
ApplicationDbContextFactory dbContextFactory,
|
ApplicationDbContextFactory dbContextFactory,
|
||||||
BTCPayNetworkProvider networkProvider,
|
BTCPayNetworkProvider networkProvider,
|
||||||
BTCPayWalletProvider walletProvider)
|
BTCPayWalletProvider walletProvider,
|
||||||
|
NBXplorerConnectionFactory nbxConnectionFactory)
|
||||||
{
|
{
|
||||||
_storeRepo = storeRepo;
|
_storeRepo = storeRepo;
|
||||||
_walletProvider = walletProvider;
|
_walletProvider = walletProvider;
|
||||||
|
_nbxConnectionFactory = nbxConnectionFactory;
|
||||||
_networkProvider = networkProvider;
|
_networkProvider = networkProvider;
|
||||||
_dbContextFactory = dbContextFactory;
|
_dbContextFactory = dbContextFactory;
|
||||||
CryptoCode = networkProvider.DefaultNetwork.CryptoCode;
|
CryptoCode = networkProvider.DefaultNetwork.CryptoCode;
|
||||||
@@ -51,16 +56,14 @@ public class StoreNumbers : ViewComponent
|
|||||||
|
|
||||||
var walletId = new WalletId(store.Id, CryptoCode);
|
var walletId = new WalletId(store.Id, CryptoCode);
|
||||||
var derivation = store.GetDerivationSchemeSettings(_networkProvider, walletId.CryptoCode);
|
var derivation = store.GetDerivationSchemeSettings(_networkProvider, walletId.CryptoCode);
|
||||||
var transactionsCount = 0;
|
int? transactionsCount = null;
|
||||||
if (derivation != null)
|
if (derivation != null && _nbxConnectionFactory.Available)
|
||||||
{
|
{
|
||||||
var network = derivation.Network;
|
await using var conn = await _nbxConnectionFactory.OpenConnection();
|
||||||
var wallet = _walletProvider.GetWallet(network);
|
var wid = NBXplorer.Client.DBUtils.nbxv1_get_wallet_id(derivation.Network.CryptoCode, derivation.AccountDerivation.ToString());
|
||||||
var allTransactions = await wallet.FetchTransactions(derivation.AccountDerivation);
|
|
||||||
var afterDate = DateTimeOffset.UtcNow - TimeSpan.FromDays(TransactionDays);
|
var afterDate = DateTimeOffset.UtcNow - TimeSpan.FromDays(TransactionDays);
|
||||||
transactionsCount = allTransactions.UnconfirmedTransactions.Transactions
|
var count = await conn.ExecuteScalarAsync<long>("SELECT COUNT(*) FROM wallets_history WHERE code=@code AND wallet_id=@wid AND seen_at > @afterDate", new { code = derivation.Network.CryptoCode, wid, afterDate });
|
||||||
.Concat(allTransactions.ConfirmedTransactions.Transactions)
|
transactionsCount = (int)count;
|
||||||
.Count(t => t.Timestamp > afterDate);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var vm = new StoreNumbersViewModel
|
var vm = new StoreNumbersViewModel
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ public class StoreNumbersViewModel
|
|||||||
public StoreData Store { get; set; }
|
public StoreData Store { get; set; }
|
||||||
public WalletId WalletId { get; set; }
|
public WalletId WalletId { get; set; }
|
||||||
public int PayoutsPending { get; set; }
|
public int PayoutsPending { get; set; }
|
||||||
public int Transactions { get; set; }
|
public int? Transactions { get; set; }
|
||||||
public int RefundsIssued { get; set; }
|
public int RefundsIssued { get; set; }
|
||||||
public int TransactionDays { get; set; }
|
public int TransactionDays { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user