mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 14:20:20 +00:00
Stories
This commit is contained in:
@@ -141,7 +141,7 @@ final class AutomaticCacheEvictionContext {
|
||||
let minPeerTimestamp = Int32(CFAbsoluteTimeGetCurrent() + NSTimeIntervalSince1970) - timeout
|
||||
//let minPeerTimestamp = Int32(CFAbsoluteTimeGetCurrent() + NSTimeIntervalSince1970)
|
||||
|
||||
return mediaBox.storageBox.all(peerId: peerId)
|
||||
let allSignal = mediaBox.storageBox.all(peerId: peerId, excludeType: MediaResourceUserContentType.story.rawValue)
|
||||
|> mapToSignal { peerResourceIds -> Signal<Never, NoError> in
|
||||
return Signal { subscriber in
|
||||
var isCancelled = false
|
||||
@@ -192,6 +192,60 @@ final class AutomaticCacheEvictionContext {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let storySignal = mediaBox.storageBox.all(peerId: peerId, onlyType: MediaResourceUserContentType.story.rawValue)
|
||||
|> mapToSignal { peerResourceIds -> Signal<Never, NoError> in
|
||||
return Signal { subscriber in
|
||||
var isCancelled = false
|
||||
|
||||
processingQueue.justDispatch {
|
||||
var removeIds: [MediaResourceId] = []
|
||||
var removeRawIds: [Data] = []
|
||||
var localCounter = 0
|
||||
for resourceId in peerResourceIds {
|
||||
localCounter += 1
|
||||
if localCounter % 100 == 0 {
|
||||
if isCancelled {
|
||||
subscriber.putCompletion()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
removeRawIds.append(resourceId)
|
||||
let id = MediaResourceId(String(data: resourceId, encoding: .utf8)!)
|
||||
let resourceTimestamp = mediaBox.resourceUsageWithInfo(id: id)
|
||||
if resourceTimestamp != 0 && resourceTimestamp < minPeerTimestamp {
|
||||
removeIds.append(id)
|
||||
}
|
||||
}
|
||||
|
||||
if !removeIds.isEmpty {
|
||||
Logger.shared.log("AutomaticCacheEviction", "peer \(peerId): cleaning \(removeIds.count) resources")
|
||||
|
||||
let _ = mediaBox.removeCachedResourcesWithResult(removeIds).start(next: { actualIds in
|
||||
var actualRawIds: [Data] = []
|
||||
for id in actualIds {
|
||||
if let data = id.stringRepresentation.data(using: .utf8) {
|
||||
actualRawIds.append(data)
|
||||
}
|
||||
}
|
||||
|
||||
mediaBox.storageBox.remove(ids: actualRawIds)
|
||||
|
||||
subscriber.putCompletion()
|
||||
})
|
||||
} else {
|
||||
subscriber.putCompletion()
|
||||
}
|
||||
}
|
||||
|
||||
return ActionDisposable {
|
||||
isCancelled = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return allSignal |> then(storySignal)
|
||||
}
|
||||
|
||||
return signals
|
||||
|
||||
Reference in New Issue
Block a user