mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-08-08 08:31:13 +00:00
Cache eviction: switch to queue to avoid stack explosion
This commit is contained in:
parent
5ec0fc43fb
commit
4adb4fa5be
@ -105,9 +105,17 @@ final class AutomaticCacheEvictionContext {
|
||||
|> mapToSignal { channelCategoryMapping -> Signal<Never, NoError> in
|
||||
var signals: Signal<Never, NoError> = .complete()
|
||||
|
||||
var matchingPeers = 0
|
||||
|
||||
let listSignal = Signal<PeerId, NoError> { subscriber in
|
||||
for peerId in peerIds {
|
||||
subscriber.putNext(peerId)
|
||||
}
|
||||
|
||||
subscriber.putCompletion()
|
||||
|
||||
return EmptyDisposable
|
||||
}
|
||||
|
||||
signals = listSignal |> mapToQueue { peerId -> Signal<Never, NoError> in
|
||||
let timeout: Int32
|
||||
if let value = settings.exceptions.first(where: { $0.key == peerId }) {
|
||||
timeout = value.value
|
||||
@ -127,15 +135,13 @@ final class AutomaticCacheEvictionContext {
|
||||
}
|
||||
|
||||
if timeout == Int32.max {
|
||||
continue
|
||||
return .complete()
|
||||
}
|
||||
|
||||
matchingPeers += 1
|
||||
|
||||
let minPeerTimestamp = Int32(CFAbsoluteTimeGetCurrent() + NSTimeIntervalSince1970) - timeout
|
||||
//let minPeerTimestamp = Int32(CFAbsoluteTimeGetCurrent() + NSTimeIntervalSince1970)
|
||||
|
||||
signals = signals |> then(mediaBox.storageBox.all(peerId: peerId)
|
||||
return mediaBox.storageBox.all(peerId: peerId)
|
||||
|> mapToSignal { peerResourceIds -> Signal<Never, NoError> in
|
||||
return Signal { subscriber in
|
||||
var isCancelled = false
|
||||
@ -185,10 +191,8 @@ final class AutomaticCacheEvictionContext {
|
||||
isCancelled = true
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Logger.shared.log("AutomaticCacheEviction", "have \(matchingPeers) peers with data")
|
||||
}
|
||||
|
||||
return signals
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user