added log for slow db

This commit is contained in:
Mikhail Filimonov 2024-03-13 16:04:07 +03:00
parent 636f35cb8e
commit 2f8fbd5fcd
2 changed files with 17 additions and 1 deletions

View File

@ -2999,6 +2999,14 @@ final class PostboxImpl {
let startTime = CFAbsoluteTimeGetCurrent() let startTime = CFAbsoluteTimeGetCurrent()
var crashDisposable: Disposable?
#if DEBUG || BETA
crashDisposable = (Signal<Void, NoError>.single(Void())
|> delay(0.1, queue: .concurrentDefaultQueue())).startStandalone(next: { _ in
preconditionFailure()
})
#endif
self.valueBox.begin() self.valueBox.begin()
let transaction = Transaction(queue: self.queue, postbox: self) let transaction = Transaction(queue: self.queue, postbox: self)
self.afterBegin(transaction: transaction) self.afterBegin(transaction: transaction)
@ -3013,6 +3021,9 @@ final class PostboxImpl {
postboxLog("Postbox transaction took \(transactionDuration * 1000.0) ms, from: \(file), on:\(line)") postboxLog("Postbox transaction took \(transactionDuration * 1000.0) ms, from: \(file), on:\(line)")
} }
crashDisposable?.dispose()
let _ = self.isInTransaction.swap(false) let _ = self.isInTransaction.swap(false)
if let currentUpdatedState = self.currentUpdatedState { if let currentUpdatedState = self.currentUpdatedState {

View File

@ -90,14 +90,18 @@ func _internal_channelMembers(postbox: Postbox, network: Network, accountPeerId:
var items: [RenderedChannelParticipant] = [] var items: [RenderedChannelParticipant] = []
switch result { switch result {
case let .channelParticipants(_, participants, chats, users): case let .channelParticipants(_, participants, chats, users):
postboxLog("channel users insertion started, count: \(participants.count)")
let parsedPeers = AccumulatedPeers(transaction: transaction, chats: chats, users: users) let parsedPeers = AccumulatedPeers(transaction: transaction, chats: chats, users: users)
postboxLog("channel users parsed")
updatePeers(transaction: transaction, accountPeerId: accountPeerId, peers: parsedPeers) updatePeers(transaction: transaction, accountPeerId: accountPeerId, peers: parsedPeers)
postboxLog("channel users postbox updated, started mapping ids")
var peers: [PeerId: Peer] = [:] var peers: [PeerId: Peer] = [:]
for id in parsedPeers.allIds { for id in parsedPeers.allIds {
if let peer = transaction.getPeer(id) { if let peer = transaction.getPeer(id) {
peers[peer.id] = peer peers[peer.id] = peer
} }
} }
postboxLog("channel users finish mapping, started updating participants")
for participant in CachedChannelParticipants(apiParticipants: participants).participants { for participant in CachedChannelParticipants(apiParticipants: participants).participants {
if let peer = parsedPeers.get(participant.peerId) { if let peer = parsedPeers.get(participant.peerId) {
@ -108,6 +112,7 @@ func _internal_channelMembers(postbox: Postbox, network: Network, accountPeerId:
items.append(RenderedChannelParticipant(participant: participant, peer: peer, peers: peers, presences: renderedPresences)) items.append(RenderedChannelParticipant(participant: participant, peer: peer, peers: peers, presences: renderedPresences))
} }
} }
postboxLog("channel participants finish updating")
case .channelParticipantsNotModified: case .channelParticipantsNotModified:
return nil return nil
} }