From 2f8fbd5fcddd7239a75e4745c7894175b453dc9c Mon Sep 17 00:00:00 2001 From: Mikhail Filimonov Date: Wed, 13 Mar 2024 16:04:07 +0300 Subject: [PATCH] added log for slow db --- submodules/Postbox/Sources/Postbox.swift | 11 +++++++++++ .../Sources/TelegramEngine/Peers/ChannelMembers.swift | 7 ++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/submodules/Postbox/Sources/Postbox.swift b/submodules/Postbox/Sources/Postbox.swift index 40a62f57d8..493a22343f 100644 --- a/submodules/Postbox/Sources/Postbox.swift +++ b/submodules/Postbox/Sources/Postbox.swift @@ -2999,6 +2999,14 @@ final class PostboxImpl { let startTime = CFAbsoluteTimeGetCurrent() + var crashDisposable: Disposable? + #if DEBUG || BETA + crashDisposable = (Signal.single(Void()) + |> delay(0.1, queue: .concurrentDefaultQueue())).startStandalone(next: { _ in + preconditionFailure() + }) + #endif + self.valueBox.begin() let transaction = Transaction(queue: self.queue, postbox: self) self.afterBegin(transaction: transaction) @@ -3013,6 +3021,9 @@ final class PostboxImpl { postboxLog("Postbox transaction took \(transactionDuration * 1000.0) ms, from: \(file), on:\(line)") } + crashDisposable?.dispose() + + let _ = self.isInTransaction.swap(false) if let currentUpdatedState = self.currentUpdatedState { diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Peers/ChannelMembers.swift b/submodules/TelegramCore/Sources/TelegramEngine/Peers/ChannelMembers.swift index 85899d79ae..05b6c9825c 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Peers/ChannelMembers.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Peers/ChannelMembers.swift @@ -90,15 +90,19 @@ func _internal_channelMembers(postbox: Postbox, network: Network, accountPeerId: var items: [RenderedChannelParticipant] = [] switch result { case let .channelParticipants(_, participants, chats, users): + postboxLog("channel users insertion started, count: \(participants.count)") let parsedPeers = AccumulatedPeers(transaction: transaction, chats: chats, users: users) + postboxLog("channel users parsed") updatePeers(transaction: transaction, accountPeerId: accountPeerId, peers: parsedPeers) + postboxLog("channel users postbox updated, started mapping ids") var peers: [PeerId: Peer] = [:] for id in parsedPeers.allIds { if let peer = transaction.getPeer(id) { peers[peer.id] = peer } } - + postboxLog("channel users finish mapping, started updating participants") + for participant in CachedChannelParticipants(apiParticipants: participants).participants { if let peer = parsedPeers.get(participant.peerId) { var renderedPresences: [PeerId: PeerPresence] = [:] @@ -108,6 +112,7 @@ func _internal_channelMembers(postbox: Postbox, network: Network, accountPeerId: items.append(RenderedChannelParticipant(participant: participant, peer: peer, peers: peers, presences: renderedPresences)) } } + postboxLog("channel participants finish updating") case .channelParticipantsNotModified: return nil }