Skip to content

Commit

Permalink
Merge pull request #6392 from nextcloud/backport/6336/stable-3.12
Browse files Browse the repository at this point in the history
[stable-3.12] Allow event processing between each XML parser run, to improve GUI performance.
  • Loading branch information
allexzander authored Jan 29, 2024
2 parents 4c91825 + b0865d7 commit 297cd01
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 15 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);
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);
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/discoveryphase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,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
2 changes: 1 addition & 1 deletion src/libsync/encryptedfoldermetadatahandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void EncryptedFolderMetadataHandler::startFetchMetadata()
void EncryptedFolderMetadataHandler::fetchFolderEncryptedId()
{
qCDebug(lcFetchAndUploadE2eeFolderMetadataJob) << "Folder is encrypted, let's get the Id from it.";
const auto job = new LsColJob(_account, _folderPath, this);
const auto job = new LsColJob(_account, _folderPath);
job->setProperties({"resourcetype", "http://owncloud.org/ns:fileid"});
connect(job, &LsColJob::directoryListingSubfolders, this, &EncryptedFolderMetadataHandler::slotFolderEncryptedIdReceived);
connect(job, &LsColJob::finishedWithError, this, &EncryptedFolderMetadataHandler::slotFolderEncryptedIdError);
Expand Down
17 changes: 13 additions & 4 deletions src/libsync/networkjobs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,13 +317,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 @@ -404,6 +404,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 @@ -414,6 +421,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/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

0 comments on commit 297cd01

Please sign in to comment.