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]>
541 lines
24 KiB
C++
541 lines
24 KiB
C++
/*
|
|
* SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
|
*/
|
|
|
|
#include "activitylistmodeltestutils.h"
|
|
#include "syncenginetestutils.h"
|
|
#include "syncresult.h"
|
|
|
|
#include <QAbstractItemModelTester>
|
|
#include <QDesktopServices>
|
|
#include <QElapsedTimer>
|
|
#include <QSignalSpy>
|
|
#include <QTest>
|
|
|
|
using namespace ActivityListModelTestUtils;
|
|
using namespace Qt::StringLiterals;
|
|
|
|
class TestActivityListModel : public QObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
TestActivityListModel() = default;
|
|
~TestActivityListModel() override
|
|
{
|
|
OCC::AccountManager::instance()->deleteAccount(accountState.data());
|
|
}
|
|
|
|
QScopedPointer<FakeQNAM> fakeQnam;
|
|
OCC::AccountPtr account;
|
|
QScopedPointer<OCC::AccountState> accountState;
|
|
|
|
OCC::Activity testNotificationActivity;
|
|
OCC::Activity testSyncResultErrorActivity;
|
|
OCC::Activity testSyncFileItemActivity;
|
|
|
|
static constexpr int searchResultsReplyDelay = 100;
|
|
|
|
QSharedPointer<TestingALM> testingALM() {
|
|
QSharedPointer<TestingALM> model(new TestingALM);
|
|
model->setAccountState(accountState.data());
|
|
QAbstractItemModelTester modelTester(model.data());
|
|
|
|
return model;
|
|
}
|
|
|
|
void testActivityAdd(void(OCC::ActivityListModel::*addingMethod)(const OCC::Activity&, OCC::ActivityListModel::ErrorType), OCC::Activity &activity) {
|
|
const auto model = testingALM();
|
|
QCOMPARE(model->rowCount(), 0);
|
|
|
|
(model.data()->*addingMethod)(activity, OCC::ActivityListModel::ErrorType::SyncError);
|
|
QCOMPARE(model->rowCount(), 1);
|
|
|
|
const auto index = model->index(0, 0);
|
|
QVERIFY(index.isValid());
|
|
}
|
|
|
|
void testActivityAdd(void(OCC::ActivityListModel::*addingMethod)(const OCC::Activity&), OCC::Activity &activity) {
|
|
const auto model = testingALM();
|
|
QCOMPARE(model->rowCount(), 0);
|
|
|
|
(model.data()->*addingMethod)(activity);
|
|
QCOMPARE(model->rowCount(), 1);
|
|
|
|
const auto index = model->index(0, 0);
|
|
QVERIFY(index.isValid());
|
|
}
|
|
|
|
void testActivityAdd(void(OCC::ActivityListModel::*addingMethod)(const OCC::Activity&, OCC::ActivityListModel::ErrorType), OCC::Activity &activity, OCC::ActivityListModel::ErrorType type) {
|
|
const auto model = testingALM();
|
|
QCOMPARE(model->rowCount(), 0);
|
|
|
|
(model.data()->*addingMethod)(activity, type);
|
|
QCOMPARE(model->rowCount(), 1);
|
|
|
|
const auto index = model->index(0, 0);
|
|
QVERIFY(index.isValid());
|
|
}
|
|
|
|
private Q_SLOTS:
|
|
void initTestCase()
|
|
{
|
|
OCC::Logger::instance()->setLogFlush(true);
|
|
OCC::Logger::instance()->setLogDebug(true);
|
|
|
|
QStandardPaths::setTestModeEnabled(true);
|
|
|
|
fakeQnam.reset(new FakeQNAM({}));
|
|
account = OCC::Account::create();
|
|
account->setCredentials(new FakeCredentials{fakeQnam.data()});
|
|
account->setUrl(QUrl(("http://example.de")));
|
|
|
|
accountState.reset(new OCC::AccountState(account));
|
|
|
|
fakeQnam->setOverride([this](QNetworkAccessManager::Operation op, const QNetworkRequest &req, QIODevice *device) {
|
|
Q_UNUSED(device)
|
|
return almTestQnamOverride(fakeQnam.data(),
|
|
op,
|
|
req,
|
|
accountState->account()->url().toString(),
|
|
this,
|
|
searchResultsReplyDelay);
|
|
});
|
|
|
|
OCC::AccountManager::instance()->addAccount(account);
|
|
|
|
const auto accName = accountState->account()->displayName();
|
|
const auto accUrl = accountState->account()->url();
|
|
|
|
testNotificationActivity = exampleNotificationActivity(accName);
|
|
testSyncResultErrorActivity = exampleSyncResultErrorActivity(accName);
|
|
testSyncFileItemActivity = exampleSyncFileItemActivity(accName, accUrl);
|
|
};
|
|
|
|
// Test receiving activity from server
|
|
void testFetchingRemoteActivity() {
|
|
const auto model = testingALM();
|
|
QCOMPARE(model->rowCount(), 0);
|
|
|
|
model->setCurrentItem(FakeRemoteActivityStorage::instance()->startingIdLast());
|
|
model->startFetchJob();
|
|
QSignalSpy activitiesJob(model.data(), &TestingALM::activitiesProcessed);
|
|
QVERIFY(activitiesJob.wait(3000));
|
|
QCOMPARE(model->rowCount(), 50);
|
|
};
|
|
|
|
// Test receiving activity from local user action
|
|
void testLocalSyncFileAction() {
|
|
testActivityAdd(&TestingALM::addSyncFileItemToActivityList, testSyncFileItemActivity);
|
|
};
|
|
|
|
void testAddNotification() {
|
|
testActivityAdd(&TestingALM::addNotificationToActivityList, testNotificationActivity);
|
|
};
|
|
|
|
void testAddError() {
|
|
testActivityAdd(&TestingALM::addErrorToActivityList, testSyncResultErrorActivity, OCC::ActivityListModel::ErrorType::SyncError);
|
|
};
|
|
|
|
void testRemoveOutdatedNotifications() {
|
|
const auto model = testingALM();
|
|
QCOMPARE(model->rowCount(), 0);
|
|
|
|
const auto removeAndAddNotifications = [&model](const OCC::ActivityList &activities) -> void {
|
|
// this is pretty much the core logic of dealing with the retrieved notifications from User::slotBuildNotificationDisplay
|
|
model->removeOutdatedNotifications(activities);
|
|
|
|
for (const auto &activity : activities) {
|
|
model->addNotificationToActivityList(activity);
|
|
}
|
|
};
|
|
|
|
const auto accName = accountState->account()->displayName();
|
|
const auto notificationOne = exampleNotificationActivity(accName, 1);
|
|
const auto notificationTwo = exampleNotificationActivity(accName, 2);
|
|
const auto notificationThree = exampleNotificationActivity(accName, 3);
|
|
|
|
removeAndAddNotifications({notificationOne});
|
|
QCOMPARE(model->rowCount(), 1);
|
|
QCOMPARE(model->activityList().count(notificationOne), 1);
|
|
QCOMPARE(model->activityList().count(notificationTwo), 0);
|
|
QCOMPARE(model->activityList().count(notificationThree), 0);
|
|
|
|
removeAndAddNotifications({notificationOne, notificationTwo});
|
|
QCOMPARE(model->rowCount(), 2);
|
|
QCOMPARE(model->activityList().count(notificationOne), 1);
|
|
QCOMPARE(model->activityList().count(notificationTwo), 1);
|
|
QCOMPARE(model->activityList().count(notificationThree), 0);
|
|
|
|
removeAndAddNotifications({notificationOne, notificationThree});
|
|
QCOMPARE(model->rowCount(), 2);
|
|
QCOMPARE(model->activityList().count(notificationOne), 1);
|
|
QCOMPARE(model->activityList().count(notificationTwo), 0);
|
|
QCOMPARE(model->activityList().count(notificationThree), 1);
|
|
|
|
removeAndAddNotifications({notificationThree});
|
|
QCOMPARE(model->rowCount(), 1);
|
|
QCOMPARE(model->activityList().count(notificationOne), 0);
|
|
QCOMPARE(model->activityList().count(notificationTwo), 0);
|
|
QCOMPARE(model->activityList().count(notificationThree), 1);
|
|
|
|
removeAndAddNotifications({});
|
|
QCOMPARE(model->rowCount(), 0);
|
|
QCOMPARE(model->activityList().count(notificationOne), 0);
|
|
QCOMPARE(model->activityList().count(notificationTwo), 0);
|
|
QCOMPARE(model->activityList().count(notificationThree), 0);
|
|
}
|
|
|
|
// Test removing activity from list
|
|
void testRemoveActivityWithRow() {
|
|
const auto model = testingALM();
|
|
QCOMPARE(model->rowCount(), 0);
|
|
|
|
model->addNotificationToActivityList(testNotificationActivity);
|
|
QCOMPARE(model->rowCount(), 1);
|
|
|
|
model->removeActivityFromActivityList(0);
|
|
QCOMPARE(model->rowCount(), 0);
|
|
}
|
|
|
|
void testRemoveActivityWithActivity() {
|
|
const auto model = testingALM();
|
|
QCOMPARE(model->rowCount(), 0);
|
|
|
|
model->addNotificationToActivityList(testNotificationActivity);
|
|
QCOMPARE(model->rowCount(), 1);
|
|
|
|
model->removeActivityFromActivityList(testNotificationActivity);
|
|
QCOMPARE(model->rowCount(), 0);
|
|
}
|
|
|
|
void testDummyFetchingActivitiesActivity() {
|
|
const auto model = testingALM();
|
|
QCOMPARE(model->rowCount(), 0);
|
|
|
|
model->setCurrentItem(FakeRemoteActivityStorage::instance()->startingIdLast());
|
|
model->startFetchJob();
|
|
|
|
// Check for the dummy before activities have arrived
|
|
QCOMPARE(model->rowCount(), 1);
|
|
|
|
QSignalSpy activitiesJob(model.data(), &TestingALM::activitiesProcessed);
|
|
QVERIFY(activitiesJob.wait(3000));
|
|
// Test the dummy was removed
|
|
QCOMPARE(model->rowCount(), 50);
|
|
}
|
|
|
|
// Test getting the data from the model
|
|
void testData() {
|
|
const auto model = testingALM();
|
|
QCOMPARE(model->rowCount(), 0);
|
|
|
|
model->setCurrentItem(FakeRemoteActivityStorage::instance()->startingIdLast());
|
|
model->startFetchJob();
|
|
QSignalSpy activitiesJob(model.data(), &TestingALM::activitiesProcessed);
|
|
QVERIFY(activitiesJob.wait(3000));
|
|
QCOMPARE(model->rowCount(), 50);
|
|
|
|
model->addSyncFileItemToActivityList(testSyncFileItemActivity);
|
|
QCOMPARE(model->rowCount(), 51);
|
|
|
|
model->addErrorToActivityList(testSyncResultErrorActivity, OCC::ActivityListModel::ErrorType::SyncError);
|
|
QCOMPARE(model->rowCount(), 52);
|
|
|
|
model->addNotificationToActivityList(testNotificationActivity);
|
|
QCOMPARE(model->rowCount(), 53);
|
|
|
|
// Test all rows for things in common
|
|
for (int i = 0; i < model->rowCount(); i++) {
|
|
const auto index = model->index(i, 0);
|
|
|
|
auto text = index.data(OCC::ActivityListModel::ActionTextRole).toString();
|
|
|
|
QVERIFY(index.data(OCC::ActivityListModel::ActionRole).canConvert<int>());
|
|
const auto type = index.data(OCC::ActivityListModel::ActionRole).toInt();
|
|
QVERIFY(type >= OCC::Activity::DummyFetchingActivityType);
|
|
|
|
QVERIFY(!index.data(OCC::ActivityListModel::AccountRole).toString().isEmpty());
|
|
QVERIFY(!index.data(OCC::ActivityListModel::ActionTextColorRole).toString().isEmpty());
|
|
QVERIFY(!index.data(OCC::ActivityListModel::IconRole).toString().isEmpty());
|
|
QVERIFY(!index.data(OCC::ActivityListModel::PointInTimeRole).toString().isEmpty());
|
|
|
|
QVERIFY(index.data(OCC::ActivityListModel::ObjectTypeRole).canConvert<int>());
|
|
QVERIFY(index.data(OCC::ActivityListModel::ObjectNameRole).canConvert<QString>());
|
|
QVERIFY(index.data(OCC::ActivityListModel::ObjectIdRole).canConvert<int>());
|
|
QVERIFY(index.data(OCC::ActivityListModel::ActionsLinksRole).canConvert<QList<QVariant>>());
|
|
QVERIFY(index.data(OCC::ActivityListModel::ActionTextRole).canConvert<QString>());
|
|
QVERIFY(index.data(OCC::ActivityListModel::MessageRole).canConvert<QString>());
|
|
QVERIFY(index.data(OCC::ActivityListModel::LinkRole).canConvert<QUrl>());
|
|
|
|
QVERIFY(index.data(OCC::ActivityListModel::ActionsLinksForActionButtonsRole).canConvert<QList<QVariant>>());
|
|
|
|
QVERIFY(index.data(OCC::ActivityListModel::AccountConnectedRole).canConvert<bool>());
|
|
QVERIFY(index.data(OCC::ActivityListModel::DisplayActions).canConvert<bool>());
|
|
|
|
QVERIFY(index.data(OCC::ActivityListModel::TalkNotificationConversationTokenRole).canConvert<QString>());
|
|
QVERIFY(index.data(OCC::ActivityListModel::TalkNotificationMessageIdRole).canConvert<QString>());
|
|
QVERIFY(index.data(OCC::ActivityListModel::TalkNotificationMessageSentRole).canConvert<QString>());
|
|
|
|
QVERIFY(index.data(OCC::ActivityListModel::ActivityRole).canConvert<OCC::Activity>());
|
|
|
|
// Unfortunately, trying to check anything relating to filepaths causes a crash
|
|
// when the folder manager is invoked by the model to look for the relevant file
|
|
}
|
|
};
|
|
|
|
void testActivityActionsData()
|
|
{
|
|
const auto model = testingALM();
|
|
QCOMPARE(model->rowCount(), 0);
|
|
model->setCurrentItem(FakeRemoteActivityStorage::instance()->startingIdLast());
|
|
|
|
int prevModelRowCount = model->rowCount();
|
|
|
|
do {
|
|
prevModelRowCount = model->rowCount();
|
|
model->startFetchJob();
|
|
QSignalSpy activitiesJob(model.data(), &TestingALM::activitiesProcessed);
|
|
QVERIFY(activitiesJob.wait(3000));
|
|
|
|
|
|
for (int i = prevModelRowCount; i < model->rowCount(); i++) {
|
|
const auto index = model->index(i, 0);
|
|
|
|
const auto actionsLinks = index.data(OCC::ActivityListModel::ActionsLinksRole).toList();
|
|
if (!actionsLinks.isEmpty()) {
|
|
const auto actionsLinksContextMenu = index.data(OCC::ActivityListModel::ActionsLinksContextMenuRole).toList();
|
|
|
|
// context menu must be shorter than total action links
|
|
QVERIFY(actionsLinksContextMenu.isEmpty() || actionsLinksContextMenu.size() < actionsLinks.size());
|
|
|
|
// context menu must not contain the primary action
|
|
QVERIFY(std::all_of(std::begin(actionsLinksContextMenu), std::end(actionsLinksContextMenu),
|
|
[&actionsLinks](const QVariant &entry) {
|
|
auto ok = false;
|
|
const auto actionIndex = entry.toMap().value(QStringLiteral("actionIndex")).toInt(&ok);
|
|
return ok && actionIndex >= 0 && actionIndex < actionsLinks.size()
|
|
&& !actionsLinks[actionIndex].value<OCC::ActivityLink>()._primary;
|
|
}));
|
|
|
|
const auto objectType = index.data(OCC::ActivityListModel::ObjectTypeRole).toString();
|
|
|
|
const auto actionButtonsLinks = index.data(OCC::ActivityListModel::ActionsLinksForActionButtonsRole).toList();
|
|
|
|
// Login attempt notification
|
|
if (objectType == QStringLiteral("2fa_id")) {
|
|
QVERIFY(actionsLinks.size() == 2);
|
|
QVERIFY(actionsLinks[0].value<OCC::ActivityLink>()._primary);
|
|
QVERIFY(!actionsLinks[1].value<OCC::ActivityLink>()._primary);
|
|
QVERIFY(actionsLinksContextMenu.isEmpty());
|
|
}
|
|
|
|
// Generate 2FA backup codes notification
|
|
if (objectType == QStringLiteral("create")) {
|
|
QVERIFY(actionsLinks.size() == 1);
|
|
QVERIFY(!actionsLinks[0].value<OCC::ActivityLink>()._primary);
|
|
QVERIFY(actionsLinksContextMenu.isEmpty());
|
|
}
|
|
|
|
// remote shares must have 'Accept' and 'Decline' actions
|
|
if (objectType == QStringLiteral("remote_share")) {
|
|
QVERIFY(actionsLinks.size() == 2);
|
|
QVERIFY(actionsLinks[0].value<OCC::ActivityLink>()._primary);
|
|
QVERIFY(actionsLinks[0].value<OCC::ActivityLink>()._verb == QStringLiteral("POST"));
|
|
QVERIFY(actionsLinks[1].value<OCC::ActivityLink>()._verb == QStringLiteral("DELETE"));
|
|
}
|
|
|
|
if ((objectType == QStringLiteral("chat") || objectType == QStringLiteral("call")
|
|
|| objectType == QStringLiteral("room"))) {
|
|
|
|
auto replyActionPos = 0;
|
|
if (objectType == QStringLiteral("call")) {
|
|
replyActionPos = 1;
|
|
}
|
|
|
|
// both action links and buttons must contain a "REPLY" verb element as secondary action
|
|
QVERIFY(actionsLinks[replyActionPos].value<OCC::ActivityLink>()._verb == QStringLiteral("REPLY"));
|
|
QCOMPARE(actionButtonsLinks[replyActionPos].toMap().value(QStringLiteral("verb")).toString(), QStringLiteral("REPLY"));
|
|
|
|
// the first action button for chat must have image set
|
|
//QVERIFY(!actionButtonsLinks[replyActionPos].value<OCC::ActivityLink>()._imageSource.isEmpty());
|
|
//QVERIFY(!actionButtonsLinks[replyActionPos].value<OCC::ActivityLink>()._imageSourceHovered.isEmpty());
|
|
|
|
// logic for "chat" and other types of activities with multiple actions
|
|
if ((objectType == QStringLiteral("chat")
|
|
|| (objectType != QStringLiteral("room") && objectType != QStringLiteral("call")))) {
|
|
|
|
// button's label for "chat" must be renamed to "Reply"
|
|
QCOMPARE(actionButtonsLinks[0].toMap().value(QStringLiteral("label")).toString(), QObject::tr("Reply"));
|
|
|
|
if (static_cast<quint32>(actionsLinks.size()) > OCC::ActivityListModel::maxActionButtons()) {
|
|
QCOMPARE(actionButtonsLinks.size(), OCC::ActivityListModel::maxActionButtons());
|
|
// in case total actions is longer than ActivityListModel::maxActionButtons, then a sum of action buttons and action menu entries must be equal to a total of action links
|
|
QCOMPARE(actionButtonsLinks.size() + actionsLinksContextMenu.size(), actionsLinks.size());
|
|
}
|
|
} else if ((objectType == QStringLiteral("call"))) {
|
|
QCOMPARE(actionButtonsLinks[0].toMap().value(QStringLiteral("label")).toString(), QStringLiteral("Call back"));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
} 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)
|
|
#include "testactivitylistmodel.moc"
|