mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Make max cache size functional again
This commit is contained in:
parent
3d821c8604
commit
880b97eaeb
@ -193,11 +193,10 @@ public final class MediaBox {
|
||||
postboxLog(string)
|
||||
}), basePath: basePath + "/storage")
|
||||
|
||||
self.timeBasedCleanup = TimeBasedCleanup(generalPaths: [
|
||||
//self.basePath,
|
||||
self.timeBasedCleanup = TimeBasedCleanup(storageBox: self.storageBox, generalPaths: [
|
||||
self.basePath + "/cache",
|
||||
self.basePath + "/animation-cache"
|
||||
], shortLivedPaths: [
|
||||
], totalSizeBasedPath: self.basePath, shortLivedPaths: [
|
||||
self.basePath + "/short-cache"
|
||||
])
|
||||
|
||||
|
@ -173,7 +173,9 @@ private func mapFiles(paths: [String], inodes: inout [InodeInfo], removeSize: UI
|
||||
|
||||
private final class TimeBasedCleanupImpl {
|
||||
private let queue: Queue
|
||||
private let storageBox: StorageBox
|
||||
private let generalPaths: [String]
|
||||
private let totalSizeBasedPath: String
|
||||
private let shortLivedPaths: [String]
|
||||
|
||||
private var scheduledTouches: [String] = []
|
||||
@ -197,9 +199,11 @@ private final class TimeBasedCleanupImpl {
|
||||
}
|
||||
}
|
||||
|
||||
init(queue: Queue, generalPaths: [String], shortLivedPaths: [String]) {
|
||||
init(queue: Queue, storageBox: StorageBox, generalPaths: [String], totalSizeBasedPath: String, shortLivedPaths: [String]) {
|
||||
self.queue = queue
|
||||
self.storageBox = storageBox
|
||||
self.generalPaths = generalPaths
|
||||
self.totalSizeBasedPath = totalSizeBasedPath
|
||||
self.shortLivedPaths = shortLivedPaths
|
||||
}
|
||||
|
||||
@ -220,6 +224,7 @@ private final class TimeBasedCleanupImpl {
|
||||
|
||||
private func resetScan(general: Int32, shortLived: Int32, gigabytesLimit: Int32) {
|
||||
let generalPaths = self.generalPaths
|
||||
let totalSizeBasedPath = self.totalSizeBasedPath
|
||||
let shortLivedPaths = self.shortLivedPaths
|
||||
let scanOnce = Signal<Never, NoError> { subscriber in
|
||||
DispatchQueue.global(qos: .background).async {
|
||||
@ -255,6 +260,14 @@ private final class TimeBasedCleanupImpl {
|
||||
removedGeneralCount += scanResult.unlinkedCount
|
||||
totalLimitSize += scanResult.totalSize
|
||||
}
|
||||
do {
|
||||
let scanResult = scanFiles(at: totalSizeBasedPath, olderThan: 0, inodes: &inodes)
|
||||
if !paths.contains(totalSizeBasedPath) {
|
||||
paths.append(totalSizeBasedPath)
|
||||
}
|
||||
removedGeneralCount += scanResult.unlinkedCount
|
||||
totalLimitSize += scanResult.totalSize
|
||||
}
|
||||
|
||||
if totalLimitSize > bytesLimit {
|
||||
mapFiles(paths: paths, inodes: &inodes, removeSize: totalLimitSize - bytesLimit)
|
||||
@ -318,10 +331,10 @@ final class TimeBasedCleanup {
|
||||
private let queue = Queue()
|
||||
private let impl: QueueLocalObject<TimeBasedCleanupImpl>
|
||||
|
||||
init(generalPaths: [String], shortLivedPaths: [String]) {
|
||||
init(storageBox: StorageBox, generalPaths: [String], totalSizeBasedPath: String, shortLivedPaths: [String]) {
|
||||
let queue = self.queue
|
||||
self.impl = QueueLocalObject(queue: self.queue, generate: {
|
||||
return TimeBasedCleanupImpl(queue: queue, generalPaths: generalPaths, shortLivedPaths: shortLivedPaths)
|
||||
return TimeBasedCleanupImpl(queue: queue, storageBox: storageBox, generalPaths: generalPaths, totalSizeBasedPath: totalSizeBasedPath, shortLivedPaths: shortLivedPaths)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -1191,15 +1191,14 @@ public class Account {
|
||||
|
||||
if !supplementary {
|
||||
let mediaBox = postbox.mediaBox
|
||||
/*self.storageSettingsDisposable = accountManager.sharedData(keys: [SharedDataKeys.cacheStorageSettings]).start(next: { [weak mediaBox] sharedData in
|
||||
let _ = (accountManager.sharedData(keys: [SharedDataKeys.cacheStorageSettings])
|
||||
|> take(1)).start(next: { [weak mediaBox] sharedData in
|
||||
guard let mediaBox = mediaBox else {
|
||||
return
|
||||
}
|
||||
let settings: CacheStorageSettings = sharedData.entries[SharedDataKeys.cacheStorageSettings]?.get(CacheStorageSettings.self) ?? CacheStorageSettings.defaultSettings
|
||||
mediaBox.setMaxStoreTimes(general: settings.defaultCacheStorageTimeout, shortLived: 60 * 60, gigabytesLimit: settings.defaultCacheStorageLimitGigabytes)
|
||||
})*/
|
||||
|
||||
mediaBox.setMaxStoreTimes(general: 1 * 24 * 60 * 60, shortLived: 60 * 60, gigabytesLimit: 100 * 1024 * 1024)
|
||||
})
|
||||
}
|
||||
|
||||
let _ = masterNotificationsKey(masterNotificationKeyValue: self.masterNotificationKey, postbox: self.postbox, ignoreDisabled: false, createIfNotExists: true).start(next: { key in
|
||||
|
Loading…
x
Reference in New Issue
Block a user