]> dgit.raspbian.org Git - nextcloud-desktop.git/commitdiff
Store duplicate indices as key-value pair with value storing bucket of all duplicates
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Thu, 17 Oct 2024 06:48:58 +0000 (14:48 +0800)
committerMatthieu Gallien <matthieu.gallien@nextcloud.com>
Fri, 18 Oct 2024 09:05:16 +0000 (11:05 +0200)
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
src/gui/filedetails/sharemodel.cpp
src/gui/filedetails/sharemodel.h

index c864993f9ec0a68340d7dddd34e1e4efde0b5e8f..23f03edf2da5b97b1343d59e5dbf001f7549c1f7 100644 (file)
@@ -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);
         }
     }
 
index 7fe2187170159b935c6970c5f3613c3fb6018071..09d136f1ea0f966690ab4b41b3d91b1385ab5a9c 100644 (file)
@@ -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