Skip to content

Commit 2bac3e4

Browse files
committed
Merge #12621: Avoid querying unnecessary model data when filtering transactions
1ee72a8 qt: Avoid querying unnecessary model data when filtering transactions (João Barbosa) Pull request description: This change moves down model data querying to where it's needed. The worst case remains the same (all data is queried and the row passes) but for the average case it improves the filter performance. Tree-SHA512: 3bcaced029cb39dfbc5377246ce76634f9050ee3a3053db4d358fcbf4d8107c649e75841f21d69f1aebcaf1bbffe3eac784e6b03b366fdbbfec1e0da8f78d8ef
2 parents df529dc + 1ee72a8 commit 2bac3e4

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

src/qt/transactionfilterproxy.cpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,31 +31,35 @@ bool TransactionFilterProxy::filterAcceptsRow(int sourceRow, const QModelIndex &
3131
{
3232
QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
3333

34-
int type = index.data(TransactionTableModel::TypeRole).toInt();
35-
QDateTime datetime = index.data(TransactionTableModel::DateRole).toDateTime();
36-
bool involvesWatchAddress = index.data(TransactionTableModel::WatchonlyRole).toBool();
37-
QString address = index.data(TransactionTableModel::AddressRole).toString();
38-
QString label = index.data(TransactionTableModel::LabelRole).toString();
39-
QString txid = index.data(TransactionTableModel::TxHashRole).toString();
40-
qint64 amount = llabs(index.data(TransactionTableModel::AmountRole).toLongLong());
4134
int status = index.data(TransactionTableModel::StatusRole).toInt();
42-
43-
if(!showInactive && status == TransactionStatus::Conflicted)
35+
if (!showInactive && status == TransactionStatus::Conflicted)
4436
return false;
45-
if(!(TYPE(type) & typeFilter))
37+
38+
int type = index.data(TransactionTableModel::TypeRole).toInt();
39+
if (!(TYPE(type) & typeFilter))
4640
return false;
41+
42+
bool involvesWatchAddress = index.data(TransactionTableModel::WatchonlyRole).toBool();
4743
if (involvesWatchAddress && watchOnlyFilter == WatchOnlyFilter_No)
4844
return false;
4945
if (!involvesWatchAddress && watchOnlyFilter == WatchOnlyFilter_Yes)
5046
return false;
51-
if(datetime < dateFrom || datetime > dateTo)
47+
48+
QDateTime datetime = index.data(TransactionTableModel::DateRole).toDateTime();
49+
if (datetime < dateFrom || datetime > dateTo)
5250
return false;
51+
52+
QString address = index.data(TransactionTableModel::AddressRole).toString();
53+
QString label = index.data(TransactionTableModel::LabelRole).toString();
54+
QString txid = index.data(TransactionTableModel::TxHashRole).toString();
5355
if (!address.contains(m_search_string, Qt::CaseInsensitive) &&
5456
! label.contains(m_search_string, Qt::CaseInsensitive) &&
5557
! txid.contains(m_search_string, Qt::CaseInsensitive)) {
5658
return false;
5759
}
58-
if(amount < minAmount)
60+
61+
qint64 amount = llabs(index.data(TransactionTableModel::AmountRole).toLongLong());
62+
if (amount < minAmount)
5963
return false;
6064

6165
return true;

0 commit comments

Comments
 (0)