File 0004-Only-trust-the-expiration-date-if-it-s-less-than-24-.patch of Package plasma5-desktop.openSUSE_Backports_SLE-15-SP3_Update

From 863ba2faa1849acd3b3fecfb111a96c171db2a29 Mon Sep 17 00:00:00 2001
From: Dan Leinir Turthra Jensen <admin@leinir.dk>
Date: Wed, 9 Feb 2022 09:23:50 +0000
Subject: [PATCH 4/5] Only trust the expiration date if it's less than 24 hours

(cherry picked from commit b85cf34298c274b5f16cb6c2aead7b87f0dabbb8)
---
 attica-kde/kdeplugin/kdeplatformdependent.cpp | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/attica-kde/kdeplugin/kdeplatformdependent.cpp b/attica-kde/kdeplugin/kdeplatformdependent.cpp
index 9864756ca..7f71d4627 100644
--- a/attica-kde/kdeplugin/kdeplatformdependent.cpp
+++ b/attica-kde/kdeplugin/kdeplatformdependent.cpp
@@ -103,7 +103,16 @@ QNetworkRequest KdePlatformDependent::removeAuthFromRequest(const QNetworkReques
     }
     for (const QString &endpoint : preferCacheEndpoints) {
         if (notConstReq.url().endsWith(endpoint)) {
-            notConstReq.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache);
+            QNetworkCacheMetaData cacheMeta{m_accessManager->cache.metaData(notConstReq.url())};
+            if (cacheMeta.isValid()) {
+                // If the expiration date is valid, but longer than 24 hours, don't trust that things
+                // haven't changed and check first, otherwise just use the cached version to relieve
+                // server strain and reduce network traffic.
+                const QDateTime tomorrow{QDateTime::currentDateTime().addDays(1)};
+                if (cacheMeta.expirationDate().isValid() && cacheMeta.expirationDate() < tomorrow) {
+                    notConstReq.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache);
+                }
+            }
             break;
         }
     }
-- 
2.33.1

openSUSE Build Service is sponsored by