Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to set the priority on a job level #9836

Merged
merged 1 commit into from
Jun 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog/unreleased/9832
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Enhancement: Run vfs downloads with a high priority

This should reduce the occurance of timeouts when downloading vfs files in the Windows explorer.

https://github.com/owncloud/client/issues/9832
11 changes: 11 additions & 0 deletions src/libsync/abstractnetworkjob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ void AbstractNetworkJob::sendRequest(const QByteArray &verb, const QUrl &url,
_verb = verb;
_request = req;
_request.setUrl(url);
_request.setPriority(_priority);
_requestBody = requestBody;
if (!isAuthenticationJob() && _account->jobQueue()->enqueue(this)) {
return;
Expand Down Expand Up @@ -442,6 +443,16 @@ void AbstractNetworkJob::abort()
}
}

void AbstractNetworkJob::setPriority(QNetworkRequest::Priority priority)
{
_priority = priority;
}

QNetworkRequest::Priority AbstractNetworkJob::priority() const
{
return _priority;
}

} // namespace OCC

QDebug operator<<(QDebug debug, const OCC::AbstractNetworkJob *job)
Expand Down
5 changes: 5 additions & 0 deletions src/libsync/abstractnetworkjob.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ class OWNCLOUDSYNC_EXPORT AbstractNetworkJob : public QObject
qint64 timeoutMsec() const { return _timer.interval(); }
bool timedOut() const { return _timedout; }

void setPriority(QNetworkRequest::Priority priority);
QNetworkRequest::Priority priority() const;

/** Returns an error message, if any. */
QString errorString() const;

Expand Down Expand Up @@ -196,6 +199,8 @@ private slots:
bool _isAuthenticationJob = false;
int _retryCount = 0;

QNetworkRequest::Priority _priority = QNetworkRequest::NormalPriority;

friend QDebug(::operator<<)(QDebug debug, const AbstractNetworkJob *job);
};

Expand Down
12 changes: 8 additions & 4 deletions src/libsync/networkjobs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,12 +314,20 @@ LsColJob::LsColJob(AccountPtr account, const QString &path, QObject *parent)
: AbstractNetworkJob(account, QString(), parent)
, _url(makeDavUrl(path))
{
// Always have a higher priority than the propagator because we use this from the UI
// and really want this to be done first (no matter what internal scheduling QNAM uses).
// Also possibly useful for avoiding false timeouts.
setPriority(QNetworkRequest::HighPriority);
}

LsColJob::LsColJob(AccountPtr account, const QUrl &url, QObject *parent)
: AbstractNetworkJob(account, QString(), parent)
, _url(url)
{
// Always have a higher priority than the propagator because we use this from the UI
// and really want this to be done first (no matter what internal scheduling QNAM uses).
// Also possibly useful for avoiding false timeouts.
setPriority(QNetworkRequest::HighPriority);
}

void LsColJob::setProperties(const QList<QByteArray> &properties)
Expand Down Expand Up @@ -582,10 +590,6 @@ void PropfindJob::start()
Q_EMIT result(values);
});
QNetworkRequest req;
// Always have a higher priority than the propagator because we use this from the UI
// and really want this to be done first (no matter what internal scheduling QNAM uses).
// Also possibly useful for avoiding false timeouts.
req.setPriority(QNetworkRequest::HighPriority);
req.setRawHeader(QByteArrayLiteral("Depth"), QByteArrayLiteral("0"));
startImpl(req);
}
Expand Down
6 changes: 4 additions & 2 deletions src/libsync/propagatedownload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ GETFileJob::GETFileJob(AccountPtr account, const QString &path, QIODevice *devic
, _resumeStart(resumeStart)
, _hasEmittedFinishedSignal(false)
{
// Long downloads must not block non-propagation jobs.
setPriority(QNetworkRequest::LowPriority);
}

GETFileJob::GETFileJob(AccountPtr account, const QUrl &url, QIODevice *device,
Expand All @@ -94,6 +96,8 @@ GETFileJob::GETFileJob(AccountPtr account, const QUrl &url, QIODevice *device,
, _directDownloadUrl(url)
, _hasEmittedFinishedSignal(false)
{
// Long downloads must not block non-propagation jobs.
setPriority(QNetworkRequest::LowPriority);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe have a common private constructor that implements this call? Redundant code is not ideal.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we already have on master

}

void GETFileJob::start()
Expand All @@ -109,8 +113,6 @@ void GETFileJob::start()
req.setRawHeader(it.key(), it.value());
}

req.setPriority(QNetworkRequest::LowPriority); // Long downloads must not block non-propagation jobs.

if (_directDownloadUrl.isEmpty()) {
sendRequest("GET", makeDavUrl(path()), req);
} else {
Expand Down
7 changes: 4 additions & 3 deletions src/libsync/propagateupload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ static bool fileIsStillChanging(const SyncFileItem &item)
PUTFileJob::PUTFileJob(AccountPtr account, const QString &path, std::unique_ptr<QIODevice> device, const QMap<QByteArray, QByteArray> &headers, int chunk, QObject *parent)
: PUTFileJob(account, Utility::concatUrlPath(account->davUrl(), path), std::move(device), headers, chunk, parent)
{
// Long uploads must not block non-propagation jobs.
setPriority(QNetworkRequest::LowPriority);
}

PUTFileJob::PUTFileJob(AccountPtr account, const QUrl &url, std::unique_ptr<QIODevice> device, const QMap<QByteArray, QByteArray> &headers, int chunk, QObject *parent)
Expand All @@ -74,6 +76,8 @@ PUTFileJob::PUTFileJob(AccountPtr account, const QUrl &url, std::unique_ptr<QIOD
, _chunk(chunk)
{
_device->setParent(this);
// Long uploads must not block non-propagation jobs.
setPriority(QNetworkRequest::LowPriority);
}

PUTFileJob::~PUTFileJob()
Expand All @@ -88,9 +92,6 @@ void PUTFileJob::start()
for (auto it = _headers.cbegin(); it != _headers.cend(); ++it) {
req.setRawHeader(it.key(), it.value());
}

req.setPriority(QNetworkRequest::LowPriority); // Long uploads must not block non-propagation jobs.

sendRequest("PUT", _url, req, _device);

connect(this, &AbstractNetworkJob::networkActivity, account().data(), &Account::propagatorNetworkActivity);
Expand Down