Skip to content

Commit

Permalink
perf: Skip registering auth delegate if it's already registered (#1715)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtrezza authored Feb 26, 2023
1 parent 701c819 commit 6d7eadd
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,19 @@ - (void)registerAuthenticationDelegate:(id<PFUserAuthenticationDelegate>)delegat
PFParameterAssert(delegate, @"Authentication delegate can't be `nil`.");
PFParameterAssert(authType, @"`authType` can't be `nil`.");

// If auth delete is already registered then unregister it gracefully
// If auth delete is already registered for provider
if ([self authenticationDelegateForAuthType:authType]) {

// If same auth delete is already registered then don't register it again
if ([self authenticationDelegateForAuthType:authType] == delegate) {
NSLog(@"skipping registering as same delegate already registered for authType `%@`.", authType);
return;
}

NSLog(@"unregistering existing deletegate to gracefully register new delegate for authType `%@`.", authType);
[self unregisterAuthenticationDelegateForAuthType:authType];
}

dispatch_sync(_dataAccessQueue, ^{
self->_authenticationDelegates[authType] = delegate;
});
Expand Down

0 comments on commit 6d7eadd

Please sign in to comment.