Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
openSUSE:Leap:15.3:Update
knewstuff.17405
0003-Add-conditional-cache-preference-to-http-r...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 0003-Add-conditional-cache-preference-to-http-requests.patch of Package knewstuff.17405
From 3d1c6074ce6f9379bbfb70b5d264f8d49fedd9e0 Mon Sep 17 00:00:00 2001 From: Dan Leinir Turthra Jensen <admin@leinir.dk> Date: Wed, 9 Feb 2022 16:17:58 +0000 Subject: [PATCH 3/3] 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 (cherry picked from commit e1c6f2bf383876a31cd3e3f9e6edcaa19dc0a7dd) --- 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 00e14522..21db43fe 100644 --- a/src/core/jobs/httpworker.cpp +++ b/src/core/jobs/httpworker.cpp @@ -40,7 +40,6 @@ public: return nam.get(request); } -private: QNetworkDiskCache cache; }; @@ -100,6 +99,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.33.1
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor