From 718aac57c6c1efc94e2ce9b70b320aee2e0e9838 Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Sat, 29 Aug 2026 23:46:20 +0200 Subject: [PATCH] Take the discarded login's feeds off disk, not just out of memory MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refusing to install a stale disk load left the file it came from intact, and the file is the half that outlives the session. The purge that moved the generation ran while the load was suspended, found the in-memory cache empty, and returned before rewriting anything; the load then discarded itself. Nobody wrote to disk, and the identity check had already recorded the new owner — so the next launch finds no mismatch and serves the previous login's private feeds to whoever is signed in now. Only the feeds are dropped. Saving the empty in-memory cache instead would take popular and trending with them, which are public and cost a cold start to fetch again, and anything the current login has already cached wins over what came off disk. --- Yattee/Services/HomeInstanceCache.swift | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Yattee/Services/HomeInstanceCache.swift b/Yattee/Services/HomeInstanceCache.swift index 48dc0d5e..70b079b1 100644 --- a/Yattee/Services/HomeInstanceCache.swift +++ b/Yattee/Services/HomeInstanceCache.swift @@ -84,6 +84,31 @@ final class HomeInstanceCache { "Discarding a disk cache that belongs to the previous login", category: .general ) + + // Not installing it is only half of it. The purge that moved + // the generation ran while this was suspended, found the + // in-memory cache empty, and returned without rewriting the + // file — so the previous login's feeds are still on disk, and + // the identity check has already recorded the new owner. The + // next launch would find no mismatch and load them. + // + // Only the feeds are private, so only the feeds are dropped: + // saving the empty in-memory cache instead would throw away + // popular and trending, which are public and cost a cold start + // to fetch again. Anything the new login has already cached + // wins over what came off disk. + var videos = cacheData.videos + var timestamps = cacheData.lastUpdated + for key in videos.keys where key.hasSuffix("_\(InstanceContentType.feed.rawValue)") { + videos.removeValue(forKey: key) + timestamps.removeValue(forKey: key) + } + videos.merge(cache) { _, current in current } + timestamps.merge(lastUpdated) { _, current in current } + + await HomeInstanceDiskCache.shared.save( + HomeInstanceDiskCache.CacheData(videos: videos, lastUpdated: timestamps) + ) return }