Skip to content

Commit 012b9fa

Browse files
committed
Merge pull request #886 from ParsePlatform/nlutsenko.latest
Add APIs to load current user, installation, config asynchronously.
2 parents 142edcd + 389ec90 commit 012b9fa

File tree

7 files changed

+50
-13
lines changed

7 files changed

+50
-13
lines changed

Parse/Internal/ParseManager.m

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -427,12 +427,15 @@ - (BFTask *)preloadDiskObjectsToMemoryAsync {
427427
@weakify(self);
428428
return [BFTask taskFromExecutor:[BFExecutor executorWithDispatchQueue:_preloadQueue] withBlock:^id{
429429
@strongify(self);
430-
[PFUser currentUser];
431-
[PFConfig currentConfig];
430+
431+
NSArray *tasks = @[
432+
[PFUser getCurrentUserInBackground],
433+
[PFConfig getCurrentConfigInBackground],
432434
#if !TARGET_OS_WATCH && !TARGET_OS_TV
433-
[PFInstallation currentInstallation];
435+
[PFInstallation getCurrentInstallationInBackground],
434436
#endif
435-
437+
];
438+
[[BFTask taskForCompletionOfAllTasks:tasks] waitUntilFinished]; // Wait synchronously to make sure we are blocking preload queue.
436439
[self eventuallyQueue];
437440

438441
return nil;

Parse/PFConfig.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ typedef void(^PFConfigResultBlock)(PFConfig *_Nullable config, NSError *_Nullabl
3838
*/
3939
+ (PFConfig *)currentConfig;
4040

41+
/**
42+
Returns the task that encapsulates the most recently fetched config.
43+
44+
If there was no config fetched - this method will return an empty instance of `PFConfig`.
45+
46+
@return Task that encapsulates current, last fetched instance of PFConfig.
47+
*/
48+
+ (BFTask<PFConfig *> *)getCurrentConfigInBackground;
49+
4150
///--------------------------------------
4251
#pragma mark - Retrieving Config
4352
///--------------------------------------

Parse/PFConfig.m

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,11 @@ + (PFConfigController *)_configController {
4040
#pragma mark Public
4141

4242
+ (PFConfig *)currentConfig {
43-
return [[[self _configController].currentConfigController getCurrentConfigAsync] waitForResult:nil
44-
withMainThreadWarning:NO];
43+
return [[self getCurrentConfigInBackground] waitForResult:nil withMainThreadWarning:NO];
44+
}
45+
46+
+ (BFTask<PFConfig *> *)getCurrentConfigInBackground {
47+
return [[self _configController].currentConfigController getCurrentConfigAsync];
4548
}
4649

4750
///--------------------------------------

Parse/PFInstallation.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,23 @@ PF_TV_UNAVAILABLE PF_WATCH_UNAVAILABLE @interface PFInstallation : PFObject<PFSu
4444
/**
4545
Gets the currently-running installation from disk and returns an instance of it.
4646
47-
If this installation is not stored on disk, returns a `PFInstallation`
48-
with `deviceType` and `installationId` fields set to those of the
49-
current installation.
47+
If this installation is not stored on disk this method will create a new `PFInstallation`
48+
with `deviceType` and `installationId` fields set to those of the current installation.
5049
5150
@result Returns a `PFInstallation` that represents the currently-running installation.
5251
*/
5352
+ (instancetype)currentInstallation;
5453

54+
/**
55+
*Asynchronously* loads the currently-running installation from disk and returns an instance of it.
56+
57+
If this installation is not stored on disk this method will create a new `PFInstallation`
58+
with `deviceType` and `installationId` fields set to those of the current installation.
59+
60+
@result Returns a task that incapsulates the current installation.
61+
*/
62+
+ (BFTask<__kindof PFInstallation *> *)getCurrentInstallationInBackground;
63+
5564
///--------------------------------------
5665
#pragma mark - Installation Properties
5766
///--------------------------------------

Parse/PFInstallation.m

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,11 @@ + (PFQuery *)query {
132132
///--------------------------------------
133133

134134
+ (instancetype)currentInstallation {
135-
BFTask *task = [[self _currentInstallationController] getCurrentObjectAsync];
136-
return [task waitForResult:nil withMainThreadWarning:NO];
135+
return [[self getCurrentInstallationInBackground] waitForResult:nil withMainThreadWarning:NO];
136+
}
137+
138+
+ (BFTask<__kindof PFInstallation *> *)getCurrentInstallationInBackground {
139+
return [[self _currentInstallationController] getCurrentObjectAsync];
137140
}
138141

139142
///--------------------------------------

Parse/PFUser.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ typedef void(^PFUserLogoutResultBlock)(NSError *_Nullable error);
4545
*/
4646
+ (nullable instancetype)currentUser;
4747

48+
/**
49+
*Asynchronously* loads the currently logged in user from disk and returns a task that encapsulates it.
50+
51+
@return The task that encapsulates the work being done.
52+
*/
53+
+ (BFTask<__kindof PFUser *> *)getCurrentUserInBackground;
54+
4855
/**
4956
The session token for the `PFUser`.
5057

Parse/PFUser.m

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -780,8 +780,11 @@ + (NSString *)parseClassName {
780780
}
781781

782782
+ (instancetype)currentUser {
783-
PFCurrentUserController *controller = [[self class] currentUserController];
784-
return [[controller getCurrentObjectAsync] waitForResult:nil withMainThreadWarning:NO];
783+
return [[self getCurrentUserInBackground] waitForResult:nil withMainThreadWarning:NO];
784+
}
785+
786+
+ (BFTask<__kindof PFUser *> *)getCurrentUserInBackground {
787+
return [[[self class] currentUserController] getCurrentObjectAsync];
785788
}
786789

787790
- (BOOL)_current {

0 commit comments

Comments
 (0)