Skip to content

Commit b1aa1e2

Browse files
committed
[Model] Maximum amount of loaded record in ram, preventing any self-spamming.
Not useful for any user to load into the UI more than 20,000 transaction records, if the wallet has them. Only will make the whole GUI slower and screw the whole user experience. This sets a limit and only shows the latest 20k txs (which is most likely still a big number for any regular user..).
1 parent 24a00fc commit b1aa1e2

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/qt/transactiontablemodel.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@
3030

3131
#define SINGLE_THREAD_MAX_TXES_SIZE 4000
3232

33+
// Maximum amount of loaded records in ram in the first load.
34+
// If the user has more and want to load them, could add a load on demand in pages.
35+
// but.. to be realistic, it's not useful anyway, why someone would ever want to have more than 20,000 txs loaded in the UI??
36+
// The person would be essentially spamming himself..
37+
#define MAX_AMOUNT_LOADED_RECORDS 20000
38+
3339
// Amount column is right-aligned it contains numbers
3440
static int column_alignments[] = {
3541
Qt::AlignLeft | Qt::AlignVCenter, /* status */
@@ -88,6 +94,21 @@ class TransactionTablePriv
8894
std::size_t txesSize = walletTxes.size();
8995
if (txesSize > SINGLE_THREAD_MAX_TXES_SIZE) {
9096

97+
// First check if the amount of txs exceeds the UI limit
98+
if (txesSize > MAX_AMOUNT_LOADED_RECORDS) {
99+
// Sort the txs by date just to be really really sure that them are ordered.
100+
// (this extra calculation should be removed in the future if can ensure that
101+
// txs are stored in order in the db, which is what should be happening)
102+
sort(walletTxes.begin(), walletTxes.end(),
103+
[](const CWalletTx & a, const CWalletTx & b) -> bool {
104+
return a.GetComputedTxTime() < b.GetComputedTxTime();
105+
});
106+
107+
// Only latest ones.
108+
walletTxes = std::vector<CWalletTx>(walletTxes.begin(), walletTxes.begin() + MAX_AMOUNT_LOADED_RECORDS);
109+
txesSize = walletTxes.size();
110+
};
111+
91112
// Simple way to get the processors count
92113
std::size_t threadsCount = (QThreadPool::globalInstance()->maxThreadCount() / 2 ) + 1;
93114

0 commit comments

Comments
 (0)