damus
damus copied to clipboard
Cache should not be backed up to iCloud
@danieldaquino
Ok, I think I found the root cause.
It seems that in order to add the profile image previews inside push notifications, we had to move the Kingfisher cache directory from the standard Caches directory inside the app's default container into our group container, which can be accessed by the notification extension — but not inside the container's cache folder:
References:
Damus version: Circa 33150a42c5a39a121a5dbd97f7b648148662b55d
damusApp.swift:
private func configureKingfisherCache() {
guard let groupURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: Constants.DAMUS_APP_GROUP_IDENTIFIER) else {
return
}
let cachePath = groupURL.appendingPathComponent(Constants.IMAGE_CACHE_DIRNAME)
if let cache = try? ImageCache(name: "sharedCache", cacheDirectoryURL: cachePath) {
KingfisherManager.shared.cache = cache
}
}
Constants.swift:
class Constants {
(...)
static let DAMUS_APP_GROUP_IDENTIFIER: String = "group.com.damus"
static let IMAGE_CACHE_DIRNAME: String = "ImageCache"
(...)
}
I will move Kingfisher data into the cache folder of the group container, as indicated by Apple documentation (1 and 2):
In iOS, the group identifier starts with the word group and a dot, followed by the group name. However, the system makes no guarantee about the group directory’s name or location in the file system. Indeed, the directory is accessible only with the file URL returned by this method. As in macOS, the system creates the directory when you need it. Unlike in macOS, when all the apps in a given app group are removed from the device, the system detects this condition and removes the corresponding group directory as well. The system creates only the
Library/Cachessubdirectory automatically, but you can create others yourself if you need them. You are free to use the group directory as you see fit, but take care to coordinate its structure among all the group’s apps. If you call the method with an invalid group identifier in iOS, the method returns a nil value.
The contents of the Library directory (with the exception of the Caches subdirectory) are backed up by iTunes and iCloud.
(Bold + italic highlights are my own)
Another note: NostrDB is also being backed up to iCloud, and it can get quite large (5.5GB on mine, I would not be surprised if some highly active users have larger files). However, moving all of NostrDB to a cache directory is problematic because we rely on it for basic app functionality (e.g. loading the user's relay list).
Created a draft for this fix: https://github.com/damus-io/damus/pull/3002
Reasoning of the fix can be found here: https://github.com/damus-io/damus/issues/2993#issuecomment-2832750054
CC @jb55 @alltheseas
This has not been properly tested, I need to do some more testing and thinking before making this PR official.
PR has been refined, tested, and marked as ready for review.