Take the discarded login's feeds off disk, not just out of memory

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.
This commit is contained in:
Arkadiusz Fal
2026-08-29 23:46:20 +02:00
parent 361f19b762
commit 718aac57c6

View File

@@ -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
}