Parse and apply profile fetches off main thread.

pull/1/head
Matthew Chen 6 years ago
parent 6239c53134
commit d717ee5411

@ -100,7 +100,7 @@ public class ProfileFetcherJob: NSObject {
DispatchQueue.main.async { DispatchQueue.main.async {
for recipientId in recipientIds { for recipientId in recipientIds {
self.updateProfile(recipientId: recipientId) self.getAndUpdateProfile(recipientId: recipientId)
} }
} }
} }
@ -109,8 +109,8 @@ public class ProfileFetcherJob: NSObject {
case throttled(lastTimeInterval: TimeInterval) case throttled(lastTimeInterval: TimeInterval)
} }
public func updateProfile(recipientId: String, remainingRetries: Int = 3) { public func getAndUpdateProfile(recipientId: String, remainingRetries: Int = 3) {
self.getProfile(recipientId: recipientId).map { profile in self.getProfile(recipientId: recipientId).map(on: DispatchQueue.global()) { profile in
self.updateProfile(signalServiceProfile: profile) self.updateProfile(signalServiceProfile: profile)
}.catch { error in }.catch { error in
switch error { switch error {
@ -120,7 +120,7 @@ public class ProfileFetcherJob: NSObject {
Logger.warn("skipping updateProfile retry. Invalid profile for: \(recipientId) error: \(error)") Logger.warn("skipping updateProfile retry. Invalid profile for: \(recipientId) error: \(error)")
default: default:
if remainingRetries > 0 { if remainingRetries > 0 {
self.updateProfile(recipientId: recipientId, remainingRetries: remainingRetries - 1) self.getAndUpdateProfile(recipientId: recipientId, remainingRetries: remainingRetries - 1)
} else { } else {
Logger.error("failed to get profile with error: \(error)") Logger.error("failed to get profile with error: \(error)")
} }
@ -153,7 +153,7 @@ public class ProfileFetcherJob: NSObject {
udAccess = udManager.udAccess(forRecipientId: recipientId, udAccess = udManager.udAccess(forRecipientId: recipientId,
requireSyncAccess: false) requireSyncAccess: false)
} }
return requestProfile(recipientId: recipientId, return requestProfile(recipientId: recipientId,
udAccess: udAccess, udAccess: udAccess,
canFailoverUDAuth: true) canFailoverUDAuth: true)
@ -175,7 +175,7 @@ public class ProfileFetcherJob: NSObject {
udAccess: udAccess, udAccess: udAccess,
canFailoverUDAuth: canFailoverUDAuth) canFailoverUDAuth: canFailoverUDAuth)
return requestMaker.makeRequest() return requestMaker.makeRequest()
.map { (result: RequestMakerResult) -> SignalServiceProfile in .map(on: DispatchQueue.global()) { (result: RequestMakerResult) -> SignalServiceProfile in
try SignalServiceProfile(recipientId: recipientId, responseObject: result.responseObject) try SignalServiceProfile(recipientId: recipientId, responseObject: result.responseObject)
} }
} }

Loading…
Cancel
Save