commit:     11c1cee5a29bc050d7ab2126f3c97932db9ce221
Author:     Andreas Sturmlechner <asturm <AT> gentoo <DOT> org>
AuthorDate: Wed Feb  9 20:22:34 2022 +0000
Commit:     Andreas Sturmlechner <asturm <AT> gentoo <DOT> org>
CommitDate: Thu Feb 10 20:09:51 2022 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=11c1cee5

kde-frameworks/knewstuff: Mitigate KNS/Discover impact on KDE servers

See also:
https://mail.kde.org/pipermail/distributions/2022-February/001140.html

Upstream commits:
c8165b7a0d622e318b3353ccf257a8f229dd12c9
e1c6f2bf383876a31cd3e3f9e6edcaa19dc0a7dd

Package-Manager: Portage-3.0.30, Repoman-3.0.3
Signed-off-by: Andreas Sturmlechner <asturm <AT> gentoo.org>

 ...f-5.90.0-add-conditional-cache-preference.patch | 61 ++++++++++++++++++++++
 ...wstuff-5.90.0-ensure-correct-ProvidersUrl.patch | 27 ++++++++++
 .../knewstuff/knewstuff-5.90.0-r1.ebuild           | 55 +++++++++++++++++++
 3 files changed, 143 insertions(+)

diff --git 
a/kde-frameworks/knewstuff/files/knewstuff-5.90.0-add-conditional-cache-preference.patch
 
b/kde-frameworks/knewstuff/files/knewstuff-5.90.0-add-conditional-cache-preference.patch
new file mode 100644
index 000000000000..80a8451ec990
--- /dev/null
+++ 
b/kde-frameworks/knewstuff/files/knewstuff-5.90.0-add-conditional-cache-preference.patch
@@ -0,0 +1,61 @@
+From e1c6f2bf383876a31cd3e3f9e6edcaa19dc0a7dd Mon Sep 17 00:00:00 2001
+From: Dan Leinir Turthra Jensen <[email protected]>
+Date: Wed, 9 Feb 2022 16:17:58 +0000
+Subject: [PATCH] Add conditional cache preference to http requests
+
+If we have a cache that's older than 7 days, assume that it's out of
+date and actually try again. If it's younger than that, assume that it's
+just the same, and prefer our cached version, if we have one.
+
+The logic here is an attempt at striking a balance between using our cache
+to its fullest potential (as in, reducing server-side load and network
+roundtrips in general) while also handling the situation where the
+information that we are fed about the cache is not entirely correct (such
+as the case where we're told there's no expiration date, but the data in
+fact does change). 7 days seems a sensible sort of deadline for that,
+though we could change that later if we need to.
+
+This was born out of a discussion on another kns review[1]
+
+Assume that no cache expiration time will be longer than 7 days, 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.
+
+[1] 
https://invent.kde.org/frameworks/knewstuff/-/merge_requests/166#note_394067
+---
+ src/core/jobs/httpworker.cpp | 12 +++++++++++-
+ 1 file changed, 11 insertions(+), 1 deletion(-)
+
+diff --git a/src/core/jobs/httpworker.cpp b/src/core/jobs/httpworker.cpp
+index b52161f6..208e1ef0 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;
+ };
+ 
+@@ -101,6 +100,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()
+-- 
+GitLab
+

diff --git 
a/kde-frameworks/knewstuff/files/knewstuff-5.90.0-ensure-correct-ProvidersUrl.patch
 
b/kde-frameworks/knewstuff/files/knewstuff-5.90.0-ensure-correct-ProvidersUrl.patch
new file mode 100644
index 000000000000..130ca3dfbd5d
--- /dev/null
+++ 
b/kde-frameworks/knewstuff/files/knewstuff-5.90.0-ensure-correct-ProvidersUrl.patch
@@ -0,0 +1,27 @@
+From c8165b7a0d622e318b3353ccf257a8f229dd12c9 Mon Sep 17 00:00:00 2001
+From: Aleix Pol <[email protected]>
+Date: Tue, 8 Feb 2022 11:48:11 +0100
+Subject: [PATCH] Engine: Ensure we are not using the wrong ProvidersUrl
+
+---
+ src/core/engine.cpp | 4 ++++
+ 1 file changed, 4 insertions(+)
+
+diff --git a/src/core/engine.cpp b/src/core/engine.cpp
+index 139dda1a..c96ba890 100644
+--- a/src/core/engine.cpp
++++ b/src/core/engine.cpp
+@@ -264,6 +264,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();
+-- 
+GitLab
+

diff --git a/kde-frameworks/knewstuff/knewstuff-5.90.0-r1.ebuild 
b/kde-frameworks/knewstuff/knewstuff-5.90.0-r1.ebuild
new file mode 100644
index 000000000000..2962ea4c6b19
--- /dev/null
+++ b/kde-frameworks/knewstuff/knewstuff-5.90.0-r1.ebuild
@@ -0,0 +1,55 @@
+# Copyright 1999-2022 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=8
+
+ECM_TEST="false"
+PVCUT=$(ver_cut 1-2)
+QTMIN=5.15.2
+inherit ecm kde.org
+
+DESCRIPTION="Framework for downloading and sharing additional application data"
+
+LICENSE="LGPL-2+"
+KEYWORDS="~amd64 ~arm ~arm64 ~ppc64 ~riscv ~x86"
+IUSE="opds"
+
+DEPEND="
+       >=dev-qt/qtdeclarative-${QTMIN}:5
+       >=dev-qt/qtgui-${QTMIN}:5
+       >=dev-qt/qtnetwork-${QTMIN}:5
+       >=dev-qt/qtwidgets-${QTMIN}:5
+       >=dev-qt/qtxml-${QTMIN}:5
+       =kde-frameworks/attica-${PVCUT}*:5
+       =kde-frameworks/karchive-${PVCUT}*:5
+       =kde-frameworks/kcompletion-${PVCUT}*:5
+       =kde-frameworks/kconfig-${PVCUT}*:5
+       =kde-frameworks/kcoreaddons-${PVCUT}*:5
+       =kde-frameworks/ki18n-${PVCUT}*:5
+       =kde-frameworks/kiconthemes-${PVCUT}*:5
+       =kde-frameworks/kio-${PVCUT}*:5
+       =kde-frameworks/kitemviews-${PVCUT}*:5
+       =kde-frameworks/kpackage-${PVCUT}*:5
+       =kde-frameworks/kservice-${PVCUT}*:5
+       =kde-frameworks/ktextwidgets-${PVCUT}*:5
+       =kde-frameworks/kwidgetsaddons-${PVCUT}*:5
+       =kde-frameworks/kxmlgui-${PVCUT}*:5
+       opds? ( =kde-frameworks/syndication-${PVCUT}*:5 )
+"
+RDEPEND="${DEPEND}
+       >=kde-frameworks/kirigami-${PVCUT}:5
+"
+
+# https://mail.kde.org/pipermail/distributions/2022-February/001140.html
+PATCHES=(
+       "${FILESDIR}/${P}-ensure-correct-ProvidersUrl.patch"
+       "${FILESDIR}/${P}-add-conditional-cache-preference.patch"
+)
+
+src_configure() {
+       local mycmakeargs=(
+               $(cmake_use_find_package opds KF5Syndication)
+       )
+
+       ecm_src_configure
+}

Reply via email to