You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
kf5-knewstuff/knewstuff-5.88.0-providersu...

59 lines
2.6 KiB

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