diff --git a/submodules/Postbox/Sources/MediaBox.swift b/submodules/Postbox/Sources/MediaBox.swift index d93ea02ddc..403858aad5 100644 --- a/submodules/Postbox/Sources/MediaBox.swift +++ b/submodules/Postbox/Sources/MediaBox.swift @@ -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" ]) diff --git a/submodules/Postbox/Sources/TimeBasedCleanup.swift b/submodules/Postbox/Sources/TimeBasedCleanup.swift index 685dbb6e09..9c5fc96258 100644 --- a/submodules/Postbox/Sources/TimeBasedCleanup.swift +++ b/submodules/Postbox/Sources/TimeBasedCleanup.swift @@ -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 { 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 - 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) }) } diff --git a/submodules/TelegramCore/Sources/Account/Account.swift b/submodules/TelegramCore/Sources/Account/Account.swift index 65adff0e40..316eb3547e 100644 --- a/submodules/TelegramCore/Sources/Account/Account.swift +++ b/submodules/TelegramCore/Sources/Account/Account.swift @@ -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