fix(activity): avoid duplicate and slow sync error entries
Ignored files with a reason are listed as sync errors. A sync folder with thousands of ignored files, for example a build folder excluded with "choose what to sync", slowed down every sync that reports them: - addErrorToActivityList() did not check whether the error was already listed, so later syncs could list the same ignored file again. - addEntriesToActivityList() rebuilt the tray preview data after every added entry, which copies and scans the whole list. - The cleanup at the start of a sync removed outdated errors one by one. Each removal moved all following entries and rebuilt the previews. Changes: - Skip an error that is already listed for the same folder. - Only rebuild the previews when an added entry can be previewed. Sync issues never are, and appended rows do not move the previewed ones. - Add removeActivitiesFromActivityList(). It removes adjacent rows at once and rebuilds the previews once. The single removal and the cleanup in User::slotProgressInfo() use it. Behavior changes: - A repeated error keeps the time it was first listed. - Adding a sync issue no longer refreshes the relative times shown in the tray previews. - Removing an activity removes all equal entries, not only the first. ActivityListModelTest covers duplicates, removal and the preview rows. Two timed tests add and remove 5000 ignored files with a 2 s limit. Debug build, 5 runs each: - add: 4.9-5.9 s before, 0.19-0.21 s after - remove one by one before: 8.0-8.5 s, in one call after: 0.10-0.13 s The change in User::slotProgressInfo() has no unit test. In a manual run with 6,466 ignored files, the cleanup took 39.8 s without the batch removal and 2.3 s with it. Related: #11047, #10962 Co-authored-by: Camila Ayres <[email protected]> Assisted-by: ClaudeCode:claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: v3DJG6GL <[email protected]>
This commit is contained in:
1 parent
8bed2ea0da
commit
2ceb1c9c6d
4 files changed
+208
-27
No files matched your search
@@ -727,7 +727,12 @@ void ActivityListModel::addEntriesToActivityList(const ActivityList &activityLis
|
||||
}
|
||||
endInsertRows();
|
||||
setHasSyncConflicts(!_conflictsList.isEmpty());
|
||||
refreshPreviewData();
|
||||
// Appended rows do not move the previewed ones, so only a new preview candidate can change the previews
|
||||
if (std::ranges::any_of(filteredList, [](const auto &activity) {
|
||||
return activity.isRecentActivityPreviewCandidate() || activity.isNotificationPreviewCandidate();
|
||||
})) {
|
||||
refreshPreviewData();
|
||||
}
|
||||
Q_EMIT activityListChanged();
|
||||
}
|
||||
|
||||
@@ -766,7 +771,12 @@ void ActivityListModel::addErrorToActivityList(const Activity &activity, const E
|
||||
break;
|
||||
}
|
||||
|
||||
if (shouldAddError) {
|
||||
// Each sync reports its errors again, e.g. every ignored file
|
||||
const auto isAlreadyListed = std::ranges::any_of(_notificationErrorsLists, [&activity](const auto &listedError) {
|
||||
return listedError == activity && listedError._folder == activity._folder;
|
||||
});
|
||||
|
||||
if (shouldAddError && !isAlreadyListed) {
|
||||
qCWarning(lcActivity) << "Error successfully added to the notification list: " << type << activity._message << activity._subject << activity._syncResultStatus << activity._syncFileItemStatus;
|
||||
auto modifiedActivity = activity;
|
||||
if (type == ErrorType::NetworkError) {
|
||||
@@ -804,35 +814,50 @@ void ActivityListModel::removeActivityFromActivityList(int row)
|
||||
|
||||
void ActivityListModel::removeActivityFromActivityList(const Activity &activity)
|
||||
{
|
||||
const auto index = _finalList.indexOf(activity);
|
||||
const auto activityWasRemoved = index != -1;
|
||||
if (index != -1) {
|
||||
beginRemoveRows({}, index, index);
|
||||
_finalList.removeAt(index);
|
||||
removeActivitiesFromActivityList({activity});
|
||||
}
|
||||
|
||||
void ActivityListModel::removeActivitiesFromActivityList(const ActivityList &activities)
|
||||
{
|
||||
if (activities.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const auto shouldRemove = [&activities](const Activity &activity) {
|
||||
return activities.contains(activity);
|
||||
};
|
||||
|
||||
// Remove adjacent rows in one go
|
||||
auto removedAny = false;
|
||||
for (auto first = qsizetype{0}; first < _finalList.size();) {
|
||||
if (!shouldRemove(_finalList.at(first))) {
|
||||
++first;
|
||||
continue;
|
||||
}
|
||||
|
||||
auto last = first;
|
||||
while (last + 1 < _finalList.size() && shouldRemove(_finalList.at(last + 1))) {
|
||||
++last;
|
||||
}
|
||||
|
||||
beginRemoveRows({}, static_cast<int>(first), static_cast<int>(last));
|
||||
_finalList.remove(first, last - first + 1);
|
||||
endRemoveRows();
|
||||
removedAny = true;
|
||||
}
|
||||
|
||||
if (activity._syncFileItemStatus == SyncFileItem::Conflict) {
|
||||
_conflictsList.removeOne(activity);
|
||||
}
|
||||
_notificationErrorsLists.removeIf(shouldRemove);
|
||||
_conflictsList.removeIf(shouldRemove);
|
||||
for (const auto &activity : activities) {
|
||||
if (activity._type != Activity::NotificationType) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (activity._type == Activity::NotificationType) {
|
||||
_activeNotificationIds.remove(activity._id);
|
||||
}
|
||||
|
||||
if (activity._type != Activity::ActivityType &&
|
||||
activity._type != Activity::DummyFetchingActivityType &&
|
||||
activity._type != Activity::DummyMoreActivitiesAvailableType &&
|
||||
activity._type != Activity::NotificationType &&
|
||||
activity._type != Activity::OpenSettingsNotificationType) {
|
||||
|
||||
const auto notificationErrorsListIndex = _notificationErrorsLists.indexOf(activity);
|
||||
if (notificationErrorsListIndex != -1) {
|
||||
_notificationErrorsLists.removeAt(notificationErrorsListIndex);
|
||||
}
|
||||
}
|
||||
|
||||
if (activityWasRemoved) {
|
||||
// Rebuilding the previews scans the whole list, so it is done once for all removed activities
|
||||
if (removedAny) {
|
||||
setHasSyncConflicts(!_conflictsList.isEmpty());
|
||||
refreshPreviewData();
|
||||
Q_EMIT activityListChanged();
|
||||
|
||||
@@ -137,6 +137,7 @@ public Q_SLOTS:
|
||||
void addSyncFileItemToActivityList(const OCC::Activity &activity);
|
||||
void removeActivityFromActivityList(int row);
|
||||
void removeActivityFromActivityList(const OCC::Activity &activity);
|
||||
void removeActivitiesFromActivityList(const OCC::ActivityList &activities);
|
||||
|
||||
void removeOutdatedNotifications(const OCC::ActivityList &receivedNotifications);
|
||||
|
||||
|
||||
@@ -1173,6 +1173,7 @@ void User::slotProgressInfo(const QString &folder, const ProgressInfo &progress)
|
||||
}
|
||||
const auto &engine = f->syncEngine();
|
||||
const auto style = engine.lastLocalDiscoveryStyle();
|
||||
auto outdatedErrors = ActivityList{};
|
||||
for (const auto errorsList = _activityModel->errorsList(); const auto &activity : errorsList) {
|
||||
if (activity._expireAtMsecs != -1) {
|
||||
// we process expired activities in a different slot
|
||||
@@ -1183,12 +1184,12 @@ void User::slotProgressInfo(const QString &folder, const ProgressInfo &progress)
|
||||
}
|
||||
|
||||
if (style == LocalDiscoveryStyle::FilesystemOnly) {
|
||||
_activityModel->removeActivityFromActivityList(activity);
|
||||
outdatedErrors.append(activity);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (const auto filePath = QString{f->path() + activity._file}; !FileSystem::fileExists(filePath)) {
|
||||
_activityModel->removeActivityFromActivityList(activity);
|
||||
outdatedErrors.append(activity);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1198,9 +1199,10 @@ void User::slotProgressInfo(const QString &folder, const ProgressInfo &progress)
|
||||
}
|
||||
|
||||
if (engine.shouldDiscoverLocally(path)) {
|
||||
_activityModel->removeActivityFromActivityList(activity);
|
||||
outdatedErrors.append(activity);
|
||||
}
|
||||
}
|
||||
_activityModel->removeActivitiesFromActivityList(outdatedErrors);
|
||||
}
|
||||
|
||||
if (progress.status() == ProgressInfo::Done) {
|
||||
|
||||
@@ -9,10 +9,12 @@
|
||||
|
||||
#include <QAbstractItemModelTester>
|
||||
#include <QDesktopServices>
|
||||
#include <QElapsedTimer>
|
||||
#include <QSignalSpy>
|
||||
#include <QTest>
|
||||
|
||||
using namespace ActivityListModelTestUtils;
|
||||
using namespace Qt::StringLiterals;
|
||||
|
||||
class TestActivityListModel : public QObject
|
||||
{
|
||||
@@ -381,6 +383,157 @@ private Q_SLOTS:
|
||||
|
||||
} while (prevModelRowCount < model->rowCount());
|
||||
};
|
||||
|
||||
// Every sync reports the same ignored files again
|
||||
void testAddError_sameErrorTwice_listedOnce()
|
||||
{
|
||||
const auto model = testingALM();
|
||||
const auto ignoredFile = exampleFileIgnoredActivity(accountState->account()->displayName());
|
||||
|
||||
model->addErrorToActivityList(ignoredFile, OCC::ActivityListModel::ErrorType::SyncError);
|
||||
model->addErrorToActivityList(ignoredFile, OCC::ActivityListModel::ErrorType::SyncError);
|
||||
|
||||
QCOMPARE(model->rowCount(), 1);
|
||||
QCOMPARE(model->errorsList().size(), 1);
|
||||
}
|
||||
|
||||
void testAddError_differentErrors_allListed()
|
||||
{
|
||||
const auto model = testingALM();
|
||||
const auto ignoredFile = exampleFileIgnoredActivity(accountState->account()->displayName());
|
||||
auto otherFile = ignoredFile;
|
||||
otherFile._id = ignoredFile._id + 1;
|
||||
otherFile._file = u"other.txt"_s;
|
||||
auto sameFileInOtherFolder = ignoredFile;
|
||||
sameFileInOtherFolder._folder = u"otherFolder"_s;
|
||||
|
||||
model->addErrorToActivityList(ignoredFile, OCC::ActivityListModel::ErrorType::SyncError);
|
||||
model->addErrorToActivityList(otherFile, OCC::ActivityListModel::ErrorType::SyncError);
|
||||
model->addErrorToActivityList(sameFileInOtherFolder, OCC::ActivityListModel::ErrorType::SyncError);
|
||||
|
||||
QCOMPARE(model->rowCount(), 3);
|
||||
QCOMPARE(model->errorsList().size(), 3);
|
||||
}
|
||||
|
||||
void testAddError_sameErrorAfterRemoval_listedAgain()
|
||||
{
|
||||
const auto model = testingALM();
|
||||
const auto ignoredFile = exampleFileIgnoredActivity(accountState->account()->displayName());
|
||||
|
||||
model->addErrorToActivityList(ignoredFile, OCC::ActivityListModel::ErrorType::SyncError);
|
||||
model->removeActivityFromActivityList(ignoredFile);
|
||||
model->addErrorToActivityList(ignoredFile, OCC::ActivityListModel::ErrorType::SyncError);
|
||||
|
||||
QCOMPARE(model->rowCount(), 1);
|
||||
QCOMPARE(model->errorsList().size(), 1);
|
||||
}
|
||||
|
||||
void testPreviewData_syncIssuesAdded_previewsStillUpdated()
|
||||
{
|
||||
const auto model = testingALM();
|
||||
const auto accountName = accountState->account()->displayName();
|
||||
|
||||
model->addErrorToActivityList(exampleFileIgnoredActivity(accountName), OCC::ActivityListModel::ErrorType::SyncError);
|
||||
QVERIFY(model->recentActivityPreviewData().isEmpty());
|
||||
QVERIFY(model->notificationPreviewData().isEmpty());
|
||||
|
||||
model->addSyncFileItemToActivityList(testSyncFileItemActivity);
|
||||
QCOMPARE(model->recentActivityPreviewData().size(), 1);
|
||||
model->addNotificationToActivityList(testNotificationActivity);
|
||||
QCOMPARE(model->notificationPreviewData().size(), 1);
|
||||
|
||||
auto secondIgnoredFile = exampleFileIgnoredActivity(accountName, {}, 5);
|
||||
secondIgnoredFile._file = u"second.txt"_s;
|
||||
model->addErrorToActivityList(secondIgnoredFile, OCC::ActivityListModel::ErrorType::SyncError);
|
||||
QCOMPARE(model->recentActivityPreviewData().size(), 1);
|
||||
QCOMPARE(model->notificationPreviewData().size(), 1);
|
||||
}
|
||||
|
||||
// A first sync can report thousands of ignored files, each added on its own
|
||||
void testAddError_manyIgnoredFiles_benchmark()
|
||||
{
|
||||
constexpr auto ignoredFileCount = 5000;
|
||||
constexpr auto maximumDurationMsecs = 2000;
|
||||
|
||||
const auto model = testingALM();
|
||||
model->addSyncFileItemToActivityList(testSyncFileItemActivity);
|
||||
model->addNotificationToActivityList(testNotificationActivity);
|
||||
const auto accountName = accountState->account()->displayName();
|
||||
|
||||
auto timer = QElapsedTimer{};
|
||||
timer.start();
|
||||
for (auto i = 0; i < ignoredFileCount; ++i) {
|
||||
auto ignoredFile = exampleFileIgnoredActivity(accountName, {}, 100 + i);
|
||||
ignoredFile._file = u"file%1.txt"_s.arg(i);
|
||||
model->addErrorToActivityList(ignoredFile, OCC::ActivityListModel::ErrorType::SyncError);
|
||||
}
|
||||
const auto durationMsecs = timer.elapsed();
|
||||
QTest::setBenchmarkResult(static_cast<qreal>(durationMsecs), QTest::WalltimeMilliseconds);
|
||||
|
||||
QCOMPARE(model->rowCount(), ignoredFileCount + 2);
|
||||
QVERIFY2(durationMsecs < maximumDurationMsecs, qPrintable(u"took %1 ms"_s.arg(durationMsecs)));
|
||||
}
|
||||
|
||||
void testRemoveActivities_someListed_removesOnlyThose()
|
||||
{
|
||||
const auto model = testingALM();
|
||||
const auto accountName = accountState->account()->displayName();
|
||||
auto ignoredFiles = OCC::ActivityList{};
|
||||
for (auto i = 0; i < 3; ++i) {
|
||||
auto ignoredFile = exampleFileIgnoredActivity(accountName, {}, 100 + i);
|
||||
ignoredFile._file = u"file%1.txt"_s.arg(i);
|
||||
model->addErrorToActivityList(ignoredFile, OCC::ActivityListModel::ErrorType::SyncError);
|
||||
ignoredFiles.append(ignoredFile);
|
||||
}
|
||||
auto notListed = exampleFileIgnoredActivity(accountName, {}, 200);
|
||||
|
||||
model->removeActivitiesFromActivityList({ignoredFiles.at(0), ignoredFiles.at(2), notListed});
|
||||
|
||||
QCOMPARE(model->rowCount(), 1);
|
||||
QCOMPARE(model->errorsList(), OCC::ActivityList{ignoredFiles.at(1)});
|
||||
}
|
||||
|
||||
void testRemoveActivities_rowsBeforePreviewedActivity_previewRowUpdated()
|
||||
{
|
||||
const auto model = testingALM();
|
||||
const auto ignoredFile = exampleFileIgnoredActivity(accountState->account()->displayName());
|
||||
model->addErrorToActivityList(ignoredFile, OCC::ActivityListModel::ErrorType::SyncError);
|
||||
model->addSyncFileItemToActivityList(testSyncFileItemActivity);
|
||||
QCOMPARE(model->recentActivityPreviewData().first().toMap().value(u"activityIndex"_s).toInt(), 1);
|
||||
|
||||
model->removeActivitiesFromActivityList({ignoredFile});
|
||||
|
||||
QCOMPARE(model->rowCount(), 1);
|
||||
QCOMPARE(model->recentActivityPreviewData().first().toMap().value(u"activityIndex"_s).toInt(), 0);
|
||||
}
|
||||
|
||||
// The next sync removes the ignored files of the previous sync before reporting them again
|
||||
void testRemoveActivities_manyIgnoredFiles_benchmark()
|
||||
{
|
||||
constexpr auto ignoredFileCount = 5000;
|
||||
constexpr auto maximumDurationMsecs = 2000;
|
||||
|
||||
const auto model = testingALM();
|
||||
model->addSyncFileItemToActivityList(testSyncFileItemActivity);
|
||||
const auto accountName = accountState->account()->displayName();
|
||||
auto ignoredFiles = OCC::ActivityList{};
|
||||
for (auto i = 0; i < ignoredFileCount; ++i) {
|
||||
auto ignoredFile = exampleFileIgnoredActivity(accountName, {}, 100 + i);
|
||||
ignoredFile._file = u"file%1.txt"_s.arg(i);
|
||||
model->addErrorToActivityList(ignoredFile, OCC::ActivityListModel::ErrorType::SyncError);
|
||||
ignoredFiles.append(ignoredFile);
|
||||
}
|
||||
|
||||
auto timer = QElapsedTimer{};
|
||||
timer.start();
|
||||
model->removeActivitiesFromActivityList(ignoredFiles);
|
||||
const auto durationMsecs = timer.elapsed();
|
||||
QTest::setBenchmarkResult(static_cast<qreal>(durationMsecs), QTest::WalltimeMilliseconds);
|
||||
|
||||
QCOMPARE(model->rowCount(), 1);
|
||||
QVERIFY(model->errorsList().isEmpty());
|
||||
QVERIFY2(durationMsecs < maximumDurationMsecs, qPrintable(u"took %1 ms"_s.arg(durationMsecs)));
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_MAIN(TestActivityListModel)
|
||||
|
||||
Reference in new issue
Block a user