mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
handle slow transactions
This commit is contained in:
parent
180e1f8141
commit
64767e6c41
@ -2994,9 +2994,11 @@ final class PostboxImpl {
|
||||
|
||||
let isInTransaction: Atomic<Bool>
|
||||
|
||||
private func internalTransaction<T>(_ f: (Transaction) -> T) -> (result: T, updatedTransactionStateVersion: Int64?, updatedMasterClientId: Int64?) {
|
||||
private func internalTransaction<T>(_ f: (Transaction) -> T, file: String = #file, line: Int = #line) -> (result: T, updatedTransactionStateVersion: Int64?, updatedMasterClientId: Int64?) {
|
||||
let _ = self.isInTransaction.swap(true)
|
||||
|
||||
let startTime = CFAbsoluteTimeGetCurrent()
|
||||
|
||||
self.valueBox.begin()
|
||||
let transaction = Transaction(queue: self.queue, postbox: self)
|
||||
self.afterBegin(transaction: transaction)
|
||||
@ -3005,6 +3007,12 @@ final class PostboxImpl {
|
||||
transaction.disposed = true
|
||||
self.valueBox.commit()
|
||||
|
||||
let endTime = CFAbsoluteTimeGetCurrent()
|
||||
let transactionDuration = endTime - startTime
|
||||
if transactionDuration > 0.1 {
|
||||
postboxLog("Postbox transaction took \(transactionDuration * 1000.0) ms, from: \(file), on:\(line)")
|
||||
}
|
||||
|
||||
let _ = self.isInTransaction.swap(false)
|
||||
|
||||
if let currentUpdatedState = self.currentUpdatedState {
|
||||
@ -3044,13 +3052,14 @@ final class PostboxImpl {
|
||||
}
|
||||
}
|
||||
|
||||
public func transaction<T>(userInteractive: Bool = false, ignoreDisabled: Bool = false, _ f: @escaping(Transaction) -> T) -> Signal<T, NoError> {
|
||||
|
||||
public func transaction<T>(userInteractive: Bool = false, ignoreDisabled: Bool = false, _ f: @escaping(Transaction) -> T, file: String = #file, line: Int = #line) -> Signal<T, NoError> {
|
||||
return Signal { subscriber in
|
||||
let f: () -> Void = {
|
||||
self.beginInternalTransaction(ignoreDisabled: ignoreDisabled, {
|
||||
let (result, updatedTransactionState, updatedMasterClientId) = self.internalTransaction({ transaction in
|
||||
return f(transaction)
|
||||
})
|
||||
}, file: file, line: line)
|
||||
|
||||
if updatedTransactionState != nil || updatedMasterClientId != nil {
|
||||
//self.pipeNotifier.notify()
|
||||
@ -4396,12 +4405,12 @@ public class Postbox {
|
||||
}
|
||||
}
|
||||
|
||||
public func transaction<T>(userInteractive: Bool = false, ignoreDisabled: Bool = false, _ f: @escaping(Transaction) -> T) -> Signal<T, NoError> {
|
||||
public func transaction<T>(userInteractive: Bool = false, ignoreDisabled: Bool = false, _ f: @escaping(Transaction) -> T, file: String = #file, line: Int = #line) -> Signal<T, NoError> {
|
||||
return Signal<T, NoError> { subscriber in
|
||||
let disposable = MetaDisposable()
|
||||
|
||||
self.impl.with { impl in
|
||||
disposable.set(impl.transaction(userInteractive: userInteractive, ignoreDisabled: ignoreDisabled, f).start(next: subscriber.putNext, error: subscriber.putError, completed: subscriber.putCompletion))
|
||||
disposable.set(impl.transaction(userInteractive: userInteractive, ignoreDisabled: ignoreDisabled, f, file: file, line: line).start(next: subscriber.putNext, error: subscriber.putError, completed: subscriber.putCompletion))
|
||||
}
|
||||
|
||||
return disposable
|
||||
|
Loading…
x
Reference in New Issue
Block a user