preload history small optimization

This commit is contained in:
Mike Renoir 2022-11-05 21:33:27 +04:00
parent 7d335e817a
commit 3eec2e834e
2 changed files with 10 additions and 3 deletions

View File

@ -330,14 +330,14 @@ public final class AccountViewTracker {
private let externallyUpdatedPeerIdDisposable = MetaDisposable()
public let chatListPreloadItems = Promise<[ChatHistoryPreloadItem]>([])
public let chatListPreloadItems = Promise<Set<ChatHistoryPreloadItem>>([])
init(account: Account) {
self.account = account
self.historyViewStateValidationContexts = HistoryViewStateValidationContexts(queue: self.queue, postbox: account.postbox, network: account.network, accountPeerId: account.peerId)
self.chatHistoryPreloadManager = ChatHistoryPreloadManager(postbox: account.postbox, network: account.network, accountPeerId: account.peerId, networkState: account.networkState, preloadItemsSignal: self.chatListPreloadItems.get() |> distinctUntilChanged)
self.chatHistoryPreloadManager = ChatHistoryPreloadManager(postbox: account.postbox, network: account.network, accountPeerId: account.peerId, networkState: account.networkState, preloadItemsSignal: self.chatListPreloadItems.get() |> distinctUntilChanged |> map { Array($0) })
self.externallyUpdatedPeerIdDisposable.set((account.stateManager.externallyUpdatedPeerIds
|> deliverOn(self.queue)).start(next: { [weak self] peerIds in

View File

@ -247,12 +247,19 @@ private final class AdditionalPreloadPeerIdsContext {
}
}
public struct ChatHistoryPreloadItem : Equatable {
public struct ChatHistoryPreloadItem : Equatable, Hashable {
public let index: ChatListIndex
public let threadId: Int64?
public let isMuted: Bool
public let hasUnread: Bool
public func hash(into hasher: inout Hasher) {
hasher.combine(index.hashValue)
if let threadId = threadId {
hasher.combine(threadId)
}
}
public init(index: ChatListIndex, threadId: Int64?, isMuted: Bool, hasUnread: Bool) {
self.index = index
self.threadId = threadId