From bc685c63efd5f69202624e22bf85e56d3e958997 Mon Sep 17 00:00:00 2001 From: Dennis Postma Date: Thu, 23 Jan 2025 20:40:41 +0100 Subject: [PATCH] Cleaned code; overwrite cache if newer results are found --- src/application/utilities.ts | 12 ++++++++++-- src/components/screens/Loading.vue | 14 +++----------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/application/utilities.ts b/src/application/utilities.ts index f2484f9..5f4f9fc 100644 --- a/src/application/utilities.ts +++ b/src/application/utilities.ts @@ -28,7 +28,7 @@ export function getDomain() { return window.location.hostname.split('.').slice(-2).join('.') } -export async function downloadCache(endpoint: string, storage: BaseStorage) { +export async function downloadCache(endpoint: string, storage: BaseStorage) { const request = await fetch(`${config.server_endpoint}/cache/${endpoint}`) const response = (await request.json()) as HttpResponse @@ -38,7 +38,15 @@ export async function downloadCache(endpoint: string, } const items = response.data ?? [] + for (const item of items) { - await storage.add(item) + let overwrite = false + const existingItem = await storage.get(item.id) + + if (!existingItem || item.updatedAt > existingItem.updatedAt) { + overwrite = true + } + + await storage.add(item, overwrite) } } \ No newline at end of file diff --git a/src/components/screens/Loading.vue b/src/components/screens/Loading.vue index 91a82bb..e943041 100644 --- a/src/components/screens/Loading.vue +++ b/src/components/screens/Loading.vue @@ -15,11 +15,7 @@