mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-28 11:48:56 +03:00
Store duplicate indices as key-value pair with value storing bucket of all duplicates
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
parent
cc4e2591ec
commit
10ff7dddbd
2 changed files with 13 additions and 11 deletions
|
@ -501,23 +501,24 @@ void ShareModel::slotSharesFetched(const QList<SharePtr> &shares)
|
|||
continue;
|
||||
}
|
||||
|
||||
auto hasDuplicates = false;
|
||||
const auto duplicateIndices = QSharedPointer<QSet<unsigned int>>::create();
|
||||
const auto handleDuplicateIndex = [this, duplicateIndices](const unsigned int idx) {
|
||||
duplicateIndices->insert(idx);
|
||||
_duplicateDisplayNameShareIndices[idx] = duplicateIndices;
|
||||
const auto targetIdx = index(idx);
|
||||
dataChanged(targetIdx, targetIdx, {Qt::DisplayRole});
|
||||
};
|
||||
|
||||
for (auto j = i + 1; j < shareCount; ++j) {
|
||||
const auto otherSharee = _shares.at(j)->getShareWith();
|
||||
if (otherSharee == nullptr || sharee->format() != otherSharee->format()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
hasDuplicates = true; // Reassign is faster
|
||||
_duplicateDisplayNameShareIndices.insert(j);
|
||||
const auto targetIndex = index(j);
|
||||
dataChanged(targetIndex, targetIndex, {Qt::DisplayRole});
|
||||
handleDuplicateIndex(j);
|
||||
}
|
||||
|
||||
if (hasDuplicates) {
|
||||
_duplicateDisplayNameShareIndices.insert(i);
|
||||
const auto targetIndex = index(i);
|
||||
dataChanged(targetIndex, targetIndex, {Qt::DisplayRole});
|
||||
if (!duplicateIndices->isEmpty()) {
|
||||
handleDuplicateIndex(i);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -253,7 +253,8 @@ private:
|
|||
QHash<QString, QPersistentModelIndex> _shareIdIndexHash;
|
||||
QHash<QString, QString> _shareIdRecentlySetPasswords;
|
||||
QVector<ShareePtr> _sharees;
|
||||
QSet<unsigned int> _duplicateDisplayNameShareIndices;
|
||||
// Buckets of sharees with the same display name
|
||||
QHash<unsigned int, QSharedPointer<QSet<unsigned int>>> _duplicateDisplayNameShareIndices;
|
||||
};
|
||||
|
||||
} // namespace OCC
|
||||
|
|
Loading…
Reference in a new issue