Add patch for providerFileUrl and caching (#2068568)

epel9
Troy Dawson 3 years ago
parent bf6a780969
commit e5a00edb02

@ -3,7 +3,7 @@
Name: kf5-%{framework}
Version: 5.90.0
Release: 1%{?dist}
Release: 2%{?dist}
Summary: KDE Frameworks 5 Tier 3 module for downloading application assets
License: LGPLv2+
@ -20,6 +20,10 @@ Source0: http://download.kde.org/%{stable}/frameworks/%{majmin}/%{framework}-%{v
## upstream patches
## Backported patches
# https://bugzilla.redhat.com/show_bug.cgi?id=2065761
Patch300: knewstuff-5.88.0-providersurl-cache.patch
# filter qml provides
%global __provides_exclude_from ^%{_kf5_qmldir}/.*\\.so$
@ -106,6 +110,9 @@ developing applications that use %{name}.
%changelog
* Fri Mar 25 2022 Troy Dawson <tdawson@redhat.com> - 5.90.0-2
- Add patch for providerFileUrl and caching (#2068568)
* Tue Jan 04 2022 Marc Deop i Argemí (Private) <marc@marcdeop.com> - 5.90.0-1
- 5.90.0

@ -0,0 +1,58 @@
From 4e7a1a65d0872bc905bd1355670397f4993b86b1 Mon Sep 17 00:00:00 2001
From: Troy Dawson <tdawson@redhat.com>
Date: Fri, 18 Mar 2022 10:54:00 -0700
Subject: [PATCH] providersurl-cache
---
src/core/engine.cpp | 4 ++++
src/core/jobs/httpworker.cpp | 12 +++++++++++-
2 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/src/core/engine.cpp b/src/core/engine.cpp
index 428af1b..9c2990c 100644
--- a/src/core/engine.cpp
+++ b/src/core/engine.cpp
@@ -265,6 +265,10 @@ bool Engine::init(const QString &configfile)
Q_EMIT uploadEnabledChanged();
m_providerFileUrl = group.readEntry("ProvidersUrl");
+ if (m_providerFileUrl == QLatin1String("https://download.kde.org/ocs/providers.xml")) {
+ m_providerFileUrl = QStringLiteral("https://autoconfig.kde.org/ocs/providers.xml");
+ qCWarning(KNEWSTUFFCORE) << "Please make sure" << configfile << "has ProvidersUrl=https://autoconfig.kde.org/ocs/providers.xml";
+ }
if (group.readEntry("UseLocalProvidersFile", "false").toLower() == QLatin1String{"true"}) {
// The local providers file is called "appname.providers", to match "appname.knsrc"
m_providerFileUrl = QUrl::fromLocalFile(QLatin1String("%1.providers").arg(configFullPath.left(configFullPath.length() - 6))).toString();
diff --git a/src/core/jobs/httpworker.cpp b/src/core/jobs/httpworker.cpp
index b81edd2..d4dd8a2 100644
--- a/src/core/jobs/httpworker.cpp
+++ b/src/core/jobs/httpworker.cpp
@@ -41,7 +41,6 @@ public:
return nam.get(request);
}
-private:
QNetworkDiskCache cache;
};
@@ -102,6 +101,17 @@ static void addUserAgent(QNetworkRequest &request)
agentHeader += QStringLiteral("-%1/%2").arg(QCoreApplication::instance()->applicationName(), QCoreApplication::instance()->applicationVersion());
}
request.setHeader(QNetworkRequest::UserAgentHeader, agentHeader);
+
+ // Assume that no cache expiration time will be longer than a week, but otherwise prefer the cache
+ // This is mildly hacky, but if we don't do this, we end up with infinite cache expirations in some
+ // cases, which of course isn't really acceptable... See ed62ee20 for a situation where that happened.
+ QNetworkCacheMetaData cacheMeta{s_httpWorkerNAM->cache.metaData(request.url())};
+ if (cacheMeta.isValid()) {
+ const QDateTime nextWeek{QDateTime::currentDateTime().addDays(7)};
+ if (cacheMeta.expirationDate().isValid() && cacheMeta.expirationDate() < nextWeek) {
+ request.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache);
+ }
+ }
}
void HTTPWorker::startRequest()
--
2.27.0
Loading…
Cancel
Save