perf(wallet): batch account presentation updates

This commit is contained in:
Ricardo Guilherme Schmidt
2026-07-17 20:38:49 -03:00
parent fc1658635b
commit 6ccd37b231
2 changed files with 51 additions and 14 deletions
+29 -5
View File
@@ -130,11 +130,21 @@ void WalletAccountModel::replaceAccounts(const QVector<WalletAccount>& accounts,
void WalletAccountModel::applyPresentations(
const QVector<WalletAccountPresentation>& presentations)
{
QHash<QString, int> rowsByAddress;
rowsByAddress.reserve(m_accounts.size());
for (int row = 0; row < m_accounts.size(); ++row) {
const QString& address = m_accounts.at(row).address;
if (!rowsByAddress.contains(address))
rowsByAddress.insert(address, row);
}
int firstChanged = m_accounts.size();
int lastChanged = -1;
for (const WalletAccountPresentation& presentation : presentations) {
const int row = indexOf(presentation.address);
if (row < 0)
const auto row = rowsByAddress.constFind(presentation.address);
if (row == rowsByAddress.cend())
continue;
Entry& entry = m_accounts[row];
Entry& entry = m_accounts[row.value()];
if (!presentation.kind.isEmpty())
entry.kind = presentation.kind;
entry.programName = presentation.programName;
@@ -147,9 +157,23 @@ void WalletAccountModel::applyPresentations(
if (!entry.canBePrimary)
entry.isPrimary = false;
updateEntryName(entry);
const QModelIndex changed = index(row);
emit dataChanged(changed, changed);
if (row.value() < firstChanged)
firstChanged = row.value();
if (row.value() > lastChanged)
lastChanged = row.value();
}
if (lastChanged < 0)
return;
emit dataChanged(index(firstChanged), index(lastChanged), {
NameRole,
KindRole,
SectionRole,
ProgramNameRole,
AccountTypeRole,
CanBePrimaryRole,
IsPrimaryRole,
DefinitionIdRole,
});
}
void WalletAccountModel::setAlias(const QString& address, const QString& alias)