Use higher priority queues for message sending

pull/214/head
nielsandriesse 5 years ago
parent b8fb751b8d
commit 620a093214

@ -5,7 +5,6 @@ public extension LokiAPI {
fileprivate static let seedNodePool: Set<String> = [ "https://storage.seed1.loki.network", "https://storage.seed3.loki.network", "https://public.loki.foundation" ]
/// Only ever modified from `LokiAPI.errorHandlingQueue` to avoid race conditions.
internal static var snodeFailureCount: [LokiAPITarget:UInt] = [:]
internal static var snodePool: Set<LokiAPITarget> = []
internal static var swarmCache: [String:[LokiAPITarget]] = [:] // TODO: Make this set based?

@ -18,8 +18,6 @@ public final class MultiDeviceProtocol : NSObject {
/// A mapping from hex encoded public key to date updated.
public static var lastDeviceLinkUpdate: [String:Date] = [:]
// TODO: I don't think stateQueue actually helps avoid race conditions
internal static var storage: OWSPrimaryStorage { OWSPrimaryStorage.shared() }
// MARK: - Settings
@ -317,10 +315,10 @@ public extension MultiDeviceProtocol {
}
if timeSinceLastUpdate > deviceLinkUpdateInterval {
let masterHexEncodedPublicKey = storage.getMasterHexEncodedPublicKey(for: hexEncodedPublicKey, in: transaction) ?? hexEncodedPublicKey
LokiFileServerAPI.getDeviceLinks(associatedWith: masterHexEncodedPublicKey).done(on: DispatchQueue.global()) { _ in
LokiFileServerAPI.getDeviceLinks(associatedWith: masterHexEncodedPublicKey).done2 { _ in
getDestinations()
lastDeviceLinkUpdate[hexEncodedPublicKey] = Date()
}.catch(on: DispatchQueue.global()) { error in
}.catch2 { error in
if (error as? LokiDotNetAPI.LokiDotNetAPIError) == LokiDotNetAPI.LokiDotNetAPIError.parsingFailed {
// Don't immediately re-fetch in case of failure due to a parsing error
lastDeviceLinkUpdate[hexEncodedPublicKey] = Date()

@ -1,8 +1,6 @@
import PromiseKit
/// Retry the promise constructed in `body` up to `maxRetryCount` times.
///
/// - Note: Intentionally explicit about the recovery queue at the call site.
internal func attempt<T>(maxRetryCount: UInt, recoveringOn queue: DispatchQueue = .global(qos: .userInitiated), body: @escaping () -> Promise<T>) -> Promise<T> {
var retryCount = 0
func attempt() -> Promise<T> {

@ -373,7 +373,7 @@ NSString *const OWSMessageSenderRateLimitedException = @"RateLimitedException";
} error:nil];
}
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
NSMutableArray<NSString *> *allAttachmentIds = [NSMutableArray new];
// This method will use a read/write transaction. This transaction

@ -147,6 +147,7 @@ public class MessageSenderJobQueue: NSObject, JobQueue {
let operationQueue = OperationQueue()
operationQueue.name = "SendingQueue:\(threadId)"
operationQueue.maxConcurrentOperationCount = 1
operationQueue.qualityOfService = .userInitiated
senderQueues[threadId] = operationQueue

@ -126,21 +126,21 @@ public extension JobQueue {
jobRecord.save(with: transaction)
transaction.addCompletionQueue(.global()) {
transaction.addCompletionQueue(DispatchQueue.global(qos: .userInitiated)) {
self.startWorkWhenAppIsReady()
}
}
func startWorkWhenAppIsReady() {
guard !CurrentAppContext().isRunningTests else {
DispatchQueue.global().async {
DispatchQueue.global(qos: .userInitiated).async {
self.workStep()
}
return
}
AppReadiness.runNowOrWhenAppDidBecomeReady {
DispatchQueue.global().async {
DispatchQueue.global(qos: .userInitiated).async {
self.workStep()
}
}
@ -190,7 +190,7 @@ public extension JobQueue {
owsFailDebug("unexpected error")
}
DispatchQueue.global().async {
DispatchQueue.global(qos: .userInitiated).async {
self.workStep()
}
}

Loading…
Cancel
Save