Cache usage experiment

This commit is contained in:
Isaac 2024-10-15 20:07:08 +04:00
parent e543bf1e2e
commit 575fa5264d
3 changed files with 16 additions and 2 deletions

View File

@ -3,9 +3,9 @@ import Foundation
public func fileSize(_ path: String, useTotalFileAllocatedSize: Bool = false) -> Int64? {
if useTotalFileAllocatedSize {
let url = URL(fileURLWithPath: path)
if let values = (try? url.resourceValues(forKeys: Set([.isRegularFileKey, .totalFileAllocatedSizeKey]))) {
if let values = (try? url.resourceValues(forKeys: Set([.isRegularFileKey, .fileAllocatedSizeKey]))) {
if values.isRegularFile ?? false {
if let fileSize = values.totalFileAllocatedSize {
if let fileSize = values.fileAllocatedSize {
return Int64(fileSize)
}
}

View File

@ -582,6 +582,14 @@ func _internal_reindexCacheInBackground(account: Account, lowImpact: Bool) -> Si
processResource(mediaMessages, representation.resource, MediaResourceUserContentType(file: file))
}
processResource(mediaMessages, file.resource, MediaResourceUserContentType(file: file))
for alternativeRepresentation in file.alternativeRepresentations {
if let alternativeRepresentation = alternativeRepresentation as? TelegramMediaFile {
for representation in alternativeRepresentation.previewRepresentations {
processResource(mediaMessages, representation.resource, MediaResourceUserContentType(file: file))
}
processResource(mediaMessages, alternativeRepresentation.resource, MediaResourceUserContentType(file: file))
}
}
} else if let webpage = media as? TelegramMediaWebpage {
if case let .Loaded(content) = webpage.content {
if let image = content.image {

View File

@ -1492,6 +1492,12 @@ private func extractAccountManagerState(records: AccountRecordsView<TelegramAcco
let timestamp = Int(CFAbsoluteTimeGetCurrent())
let minReindexTimestamp = timestamp - 2 * 24 * 60 * 60
if let indexTimestamp = UserDefaults.standard.object(forKey: "TelegramCacheIndexTimestamp") as? NSNumber, indexTimestamp.intValue >= minReindexTimestamp {
#if DEBUG && false
Logger.shared.log("App \(self.episodeId)", "Executing low-impact cache reindex in foreground")
let _ = self.runCacheReindexTasks(lowImpact: true, completion: {
Logger.shared.log("App \(self.episodeId)", "Executing low-impact cache reindex in foreground — done1")
})
#endif
} else {
UserDefaults.standard.set(timestamp as NSNumber, forKey: "TelegramCacheIndexTimestamp")