Skip to content

Commit

Permalink
Allow event processing between each XML parser run, to improve GUI pe…
Browse files Browse the repository at this point in the history
…rformance.

Signed-off-by: alex-z <[email protected]>
  • Loading branch information
allexzander committed Jan 5, 2024
1 parent 4714e01 commit b51e474
Show file tree
Hide file tree
Showing 14 changed files with 28 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/gui/editlocallyjob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ void EditLocallyJob::fetchRemoteFileParentInfo()
return;
}

const auto job = new LsColJob(_accountState->account(), QDir::cleanPath(_folderForFile->remotePathTrailingSlash() + _relPathParent), this);
const auto job = new LsColJob(_accountState->account(), QDir::cleanPath(_folderForFile->remotePathTrailingSlash() + _relPathParent));
const QList<QByteArray> props{QByteArrayLiteral("resourcetype"),
QByteArrayLiteral("getlastmodified"),
QByteArrayLiteral("getetag"),
Expand Down
2 changes: 1 addition & 1 deletion src/gui/folderstatusmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ void FolderStatusModel::fetchMore(const QModelIndex &parent)
path += infoPath;
}

auto *job = new LsColJob(_accountState->account(), path, this);
auto *job = new LsColJob(_accountState->account(), path);
info->_fetchingJob = job;
auto props = QList<QByteArray>() << "resourcetype"
<< "http://owncloud.org/ns:size"
Expand Down
2 changes: 1 addition & 1 deletion src/gui/folderwizard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ void FolderWizardRemotePath::slotTypedPathFound(const QStringList &subpaths)

LsColJob *FolderWizardRemotePath::runLsColJob(const QString &path)
{
auto *job = new LsColJob(_account, path, this);
auto *job = new LsColJob(_account, path);
auto props = QList<QByteArray>() << "resourcetype";
if (_account->capabilities().clientSideEncryptionAvailable()) {
props << "http://nextcloud.org/ns:is-encrypted";
Expand Down
4 changes: 2 additions & 2 deletions src/gui/selectivesyncdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ void SelectiveSyncWidget::refreshFolders()
{
_encryptedPaths.clear();

auto *job = new LsColJob(_account, _folderPath, this);
auto *job = new LsColJob(_account, _folderPath);

Check warning on line 110 in src/gui/selectivesyncdialog.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/selectivesyncdialog.cpp:110:11 [cppcoreguidelines-init-variables]

variable 'job' is not initialized
auto props = QList<QByteArray>() << "resourcetype"
<< "http://owncloud.org/ns:size";
if (_account->capabilities().clientSideEncryptionAvailable()) {
Expand Down Expand Up @@ -336,7 +336,7 @@ void SelectiveSyncWidget::slotItemExpanded(QTreeWidgetItem *item)
if (!_folderPath.isEmpty()) {
prefix = _folderPath + QLatin1Char('/');
}
auto *job = new LsColJob(_account, prefix + dir, this);
auto *job = new LsColJob(_account, prefix + dir);

Check warning on line 339 in src/gui/selectivesyncdialog.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/selectivesyncdialog.cpp:339:11 [cppcoreguidelines-init-variables]

variable 'job' is not initialized
job->setProperties(QList<QByteArray>() << "resourcetype"
<< "http://owncloud.org/ns:size");
connect(job, &LsColJob::directoryListingSubfolders,
Expand Down
2 changes: 1 addition & 1 deletion src/gui/shellextensionsserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ void ShellExtensionsServer::processCustomStateRequest(QLocalSocket *socket, cons
closeSession(socket);
}));

auto *const lsColJob = new LsColJob(folder->accountState()->account(), QDir::cleanPath(folder->remotePath() + lsColJobPath), this);
auto *const lsColJob = new LsColJob(folder->accountState()->account(), QDir::cleanPath(folder->remotePath() + lsColJobPath));
lsColJob->setProperties({QByteArrayLiteral("http://owncloud.org/ns:share-types"), QByteArrayLiteral("http://owncloud.org/ns:permissions")});

const auto folderAlias = customStateRequestInfo.folderAlias;
Expand Down
2 changes: 1 addition & 1 deletion src/libsync/abstractpropagateremotedeleteencrypted.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void AbstractPropagateRemoteDeleteEncrypted::storeFirstErrorString(const QString
void AbstractPropagateRemoteDeleteEncrypted::startLsColJob(const QString &path)
{
qCDebug(ABSTRACT_PROPAGATE_REMOVE_ENCRYPTED) << "Folder is encrypted, let's get the Id from it.";
auto job = new LsColJob(_propagator->account(), _propagator->fullRemotePath(path), this);
auto job = new LsColJob(_propagator->account(), _propagator->fullRemotePath(path));
job->setProperties({"resourcetype", "http://owncloud.org/ns:fileid"});
connect(job, &LsColJob::directoryListingSubfolders, this, &AbstractPropagateRemoteDeleteEncrypted::slotFolderEncryptedIdReceived);
connect(job, &LsColJob::finishedWithError, this, &AbstractPropagateRemoteDeleteEncrypted::taskFailed);
Expand Down
2 changes: 1 addition & 1 deletion src/libsync/discoveryphase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ DiscoverySingleDirectoryJob::DiscoverySingleDirectoryJob(const AccountPtr &accou
void DiscoverySingleDirectoryJob::start()
{
// Start the actual HTTP job
auto *lsColJob = new LsColJob(_account, _subPath, this);
auto *lsColJob = new LsColJob(_account, _subPath);

QList<QByteArray> props;
props << "resourcetype"
Expand Down
17 changes: 13 additions & 4 deletions src/libsync/networkjobs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,13 +316,13 @@ bool LsColXMLParser::parse(const QByteArray &xml, QHash<QString, ExtraFolderInfo

/*********************************************************************************************/

LsColJob::LsColJob(AccountPtr account, const QString &path, QObject *parent)
: AbstractNetworkJob(account, path, parent)
LsColJob::LsColJob(AccountPtr account, const QString &path)
: AbstractNetworkJob(account, path)
{
}

LsColJob::LsColJob(AccountPtr account, const QUrl &url, QObject *parent)
: AbstractNetworkJob(account, QString(), parent)
LsColJob::LsColJob(AccountPtr account, const QUrl &url)
: AbstractNetworkJob(account, QString())
, _url(url)
{
}
Expand Down Expand Up @@ -403,6 +403,13 @@ bool LsColJob::finished()
connect(&parser, &LsColXMLParser::finishedWithoutError,
this, &LsColJob::finishedWithoutError);

// bool LsColXMLParser::parse takes a while, let's process some events in attempt to make UI more responsive
// from https://doc.qt.io/qt-5/qcoreapplication.html#processEvents-1
// "You can call this function occasionally when your program is busy doing a long operation (e.g. copying a file)."
// we should not abuse this function, as it affects QObject instances lifetime (when children are getting deleted or when deleteLater is called)
// one reason I had to remove ability for LsColJob to have parent, which, otherwise, leads to a crash later
QCoreApplication::processEvents(QEventLoop::AllEvents, 100);

QString expectedPath = reply()->request().url().path(); // something like "/owncloud/remote.php/dav/folder"
if (!parser.parse(reply()->readAll(), &_folderInfos, expectedPath)) {
// XML parse error
Expand All @@ -413,6 +420,8 @@ bool LsColJob::finished()
emit finishedWithError(reply());
}

this->deleteLater();

return true;
}

Expand Down
4 changes: 2 additions & 2 deletions src/libsync/networkjobs.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ class OWNCLOUDSYNC_EXPORT LsColJob : public AbstractNetworkJob
{
Q_OBJECT
public:
explicit LsColJob(AccountPtr account, const QString &path, QObject *parent = nullptr);
explicit LsColJob(AccountPtr account, const QUrl &url, QObject *parent = nullptr);
explicit LsColJob(AccountPtr account, const QString &path);
explicit LsColJob(AccountPtr account, const QUrl &url);
void start() override;
QHash<QString, ExtraFolderInfo> _folderInfos;

Expand Down
2 changes: 1 addition & 1 deletion src/libsync/propagatedownloadencrypted.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void PropagateDownloadEncrypted::start()
const auto remoteParentPath = remotePath.left(remotePath.lastIndexOf('/'));

// Is encrypted Now we need the folder-id
auto job = new LsColJob(_propagator->account(), remoteParentPath, this);
auto job = new LsColJob(_propagator->account(), remoteParentPath);
job->setProperties({"resourcetype", "http://owncloud.org/ns:fileid"});
connect(job, &LsColJob::directoryListingSubfolders,
this, &PropagateDownloadEncrypted::checkFolderId);
Expand Down
2 changes: 1 addition & 1 deletion src/libsync/propagateuploadencrypted.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void PropagateUploadEncrypted::start()
* unlock the folder.
*/
qCDebug(lcPropagateUploadEncrypted) << "Folder is encrypted, let's get the Id from it.";
auto job = new LsColJob(_propagator->account(), absoluteRemoteParentPath, this);
auto job = new LsColJob(_propagator->account(), absoluteRemoteParentPath);
job->setProperties({"resourcetype", "http://owncloud.org/ns:fileid"});
connect(job, &LsColJob::directoryListingSubfolders, this, &PropagateUploadEncrypted::slotFolderEncryptedIdReceived);
connect(job, &LsColJob::finishedWithError, this, &PropagateUploadEncrypted::slotFolderEncryptedIdError);
Expand Down
2 changes: 1 addition & 1 deletion src/libsync/propagateuploadng.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void PropagateUploadFileNG::doStartUpload()
if (progressInfo._valid && progressInfo.isChunked() && progressInfo._modtime == _item->_modtime && progressInfo._size == _item->_size) {
_transferId = progressInfo._transferid;

const auto job = new LsColJob(propagator()->account(), chunkUploadFolderUrl(), this);
const auto job = new LsColJob(propagator()->account(), chunkUploadFolderUrl());
_jobs.append(job);
job->setProperties(QList<QByteArray>() << "resourcetype"
<< "getcontentlength");
Expand Down
2 changes: 1 addition & 1 deletion src/libsync/updatefiledropmetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ UpdateFileDropMetadataJob::UpdateFileDropMetadataJob(OwncloudPropagator *propaga
void UpdateFileDropMetadataJob::start()
{
qCDebug(lcUpdateFileDropMetadataJob) << "Folder is encrypted, let's get the Id from it.";
const auto fetchFolderEncryptedIdJob = new LsColJob(propagator()->account(), _path, this);
const auto fetchFolderEncryptedIdJob = new LsColJob(propagator()->account(), _path);
fetchFolderEncryptedIdJob->setProperties({"resourcetype", "http://owncloud.org/ns:fileid"});
connect(fetchFolderEncryptedIdJob, &LsColJob::directoryListingSubfolders, this, &UpdateFileDropMetadataJob::slotFolderEncryptedIdReceived);
connect(fetchFolderEncryptedIdJob, &LsColJob::finishedWithError, this, &UpdateFileDropMetadataJob::slotFolderEncryptedIdError);
Expand Down
2 changes: 1 addition & 1 deletion src/libsync/vfs/cfapi/hydrationjob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ void OCC::HydrationJob::handleNewConnectionForEncryptedFile()
const auto remotePath = QString(rootPath + remoteFilename);
const auto remoteParentPath = remotePath.left(remotePath.lastIndexOf('/'));

auto job = new LsColJob(_account, remoteParentPath, this);
auto job = new LsColJob(_account, remoteParentPath);
job->setProperties({ "resourcetype", "http://owncloud.org/ns:fileid" });
connect(job, &LsColJob::directoryListingSubfolders,
this, &HydrationJob::slotCheckFolderId);
Expand Down

0 comments on commit b51e474

Please sign in to comment.