From 8422d24028eff3823085179536df6b4629def405 Mon Sep 17 00:00:00 2001 From: Salvador Cipolla Date: Mon, 3 Feb 2025 19:04:10 -0300 Subject: [PATCH 1/2] Only check if files in cache are outdated once per session or reload --- Knossos.NET/Classes/KnUtils.cs | 21 ++++++++++++++++++++- Knossos.NET/Classes/Knossos.cs | 1 + 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Knossos.NET/Classes/KnUtils.cs b/Knossos.NET/Classes/KnUtils.cs index 5d1d1c07..21043baf 100644 --- a/Knossos.NET/Classes/KnUtils.cs +++ b/Knossos.NET/Classes/KnUtils.cs @@ -85,6 +85,21 @@ static KnUtils() public static bool IsAppImage => isAppImage; public static string AppImagePath => appImagePath; + /// + /// Keeps a list of remote resources loaded to cache(or checked) during this session + /// So we don't constantly query these remote URLs for changes + /// + private static List remoteResourceLoadedToCache = new List(); + + /// + /// Clear list of remote url resources downloaded to cache (or checked) during this session + /// So they can be checked and redownloaded again whiout restarting if they are outdated. + /// + public static void ClearDownloadedRemoteResourceList() + { + remoteResourceLoadedToCache.Clear(); + } + /// /// Full path to AppImage file /// @@ -673,6 +688,7 @@ public static string GetCachePath() var fileInCacheEtagPath = fileInCachePath + ".etag"; string? remoteEtag = null; bool cacheFileExists = File.Exists(fileInCachePath); + bool cachedOrCheckedDuringThisSession = remoteResourceLoadedToCache.Contains(resourceURL); Uri uri = new Uri(resourceURL); bool isNebulaFile = Nebula.nebulaMirrors.Contains(uri.Host.ToLower()); cacheFileIsValid = cacheFileExists && new FileInfo(fileInCachePath).Length > 0 ? true : false; @@ -681,9 +697,10 @@ public static string GetCachePath() if (cacheFileIsValid && cacheFileExists) { bool cacheFileEtagExists = File.Exists(fileInCacheEtagPath); - if (isNebulaFile) + if (isNebulaFile || cachedOrCheckedDuringThisSession) { //This is a nebula file, nebula files are stored by their checksum so they never update + //Or we already downloaded or checked this file during this session, lets not do it again return fileInCachePath; } else if (cacheFileEtagExists) @@ -694,6 +711,7 @@ public static string GetCachePath() if (cachedEtag != null && cachedEtag == remoteEtag) { //cache is up to date + remoteResourceLoadedToCache.Add(resourceURL); return fileInCachePath; } else @@ -736,6 +754,7 @@ public static string GetCachePath() Log.Add(Log.LogSeverity.Error, "KnUtils.GetRemoteResource()", ex); } } + remoteResourceLoadedToCache.Add(resourceURL); return fileInCachePath; } catch (Exception ex) diff --git a/Knossos.NET/Classes/Knossos.cs b/Knossos.NET/Classes/Knossos.cs index a4ba8791..33da8912 100644 --- a/Knossos.NET/Classes/Knossos.cs +++ b/Knossos.NET/Classes/Knossos.cs @@ -765,6 +765,7 @@ public static void ResetBasePath() TaskViewModel.Instance?.CancelAllRunningTasks(); Nebula.CancelOperations(); await Task.Delay(2000).ConfigureAwait(false); + KnUtils.ClearDownloadedRemoteResourceList(); LoadBasePath(); }); } From a96f820796b81c958c1e570ce7b2d1bf0de9952d Mon Sep 17 00:00:00 2001 From: Salvador Cipolla Date: Mon, 3 Feb 2025 20:50:55 -0300 Subject: [PATCH 2/2] typo --- Knossos.NET/Classes/KnUtils.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Knossos.NET/Classes/KnUtils.cs b/Knossos.NET/Classes/KnUtils.cs index 21043baf..a21d798d 100644 --- a/Knossos.NET/Classes/KnUtils.cs +++ b/Knossos.NET/Classes/KnUtils.cs @@ -86,14 +86,14 @@ static KnUtils() public static string AppImagePath => appImagePath; /// - /// Keeps a list of remote resources loaded to cache(or checked) during this session + /// Keeps a list of remote resources loaded to cache (or checked) during this session /// So we don't constantly query these remote URLs for changes /// private static List remoteResourceLoadedToCache = new List(); /// /// Clear list of remote url resources downloaded to cache (or checked) during this session - /// So they can be checked and redownloaded again whiout restarting if they are outdated. + /// So they can be checked and redownloaded again without restarting if they are outdated. /// public static void ClearDownloadedRemoteResourceList() {