Skip to content

Commit

Permalink
Store duplicate indices as key-value pair with value storing bucket o…
Browse files Browse the repository at this point in the history
…f all duplicates

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
  • Loading branch information
claucambra authored and mgallien committed Oct 18, 2024
1 parent 4ffebe7 commit 5493403
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
21 changes: 11 additions & 10 deletions src/gui/filedetails/sharemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/gui/filedetails/sharemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ private slots:
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

0 comments on commit 5493403

Please sign in to comment.