Batch the creation of fake contacts.

// FREEBIE
This commit is contained in:
Matthew Chen 2017-09-01 13:02:01 -04:00
parent 49147a4991
commit a35a21d5cc
2 changed files with 32 additions and 1 deletions

View File

@ -1136,7 +1136,6 @@ NS_ASSUME_NONNULL_BEGIN
+ (void)createRandomContacts:(NSUInteger)count
{
OWSAssert(count > 0);
[self createRandomContacts:count contactHandler:nil];
}
@ -1144,6 +1143,31 @@ NS_ASSUME_NONNULL_BEGIN
contactHandler:
(nullable void (^)(CNContact *_Nonnull contact, NSUInteger idx, BOOL *_Nonnull stop))contactHandler
{
OWSAssert(count > 0);
NSUInteger remainder = count;
const NSUInteger kMaxBatchSize = 20;
NSUInteger batch = MIN(kMaxBatchSize, remainder);
remainder -= batch;
[self createRandomContactsBatch:batch
contactHandler:nil
batchCompletionHandler:^{
if (remainder > 0) {
[self createRandomContacts:remainder contactHandler:contactHandler];
}
}];
}
+ (void)createRandomContactsBatch:(NSUInteger)count
contactHandler:(nullable void (^)(
CNContact *_Nonnull contact, NSUInteger idx, BOOL *_Nonnull stop))contactHandler
batchCompletionHandler:(nullable void (^)())batchCompletionHandler
{
OWSAssert(count > 0);
OWSAssert(batchCompletionHandler);
DDLogDebug(@"createRandomContactsBatch: %zd", count);
CNAuthorizationStatus status = [CNContactStore authorizationStatusForEntityType:CNEntityTypeContacts];
if (status == CNAuthorizationStatusDenied || status == CNAuthorizationStatusRestricted) {
[OWSAlerts showAlertWithTitle:@"Error" message:@"No contacts access."];
@ -1203,6 +1227,9 @@ NS_ASSUME_NONNULL_BEGIN
[contacts enumerateObjectsUsingBlock:contactHandler];
}
}
if (batchCompletionHandler) {
batchCompletionHandler();
}
}];
}

View File

@ -101,6 +101,10 @@ NS_ASSUME_NONNULL_BEGIN
actionBlock:^{
[DebugUIMessages createFakeThreads:100 withFakeMessages:100];
}],
[OWSTableItem itemWithTitle:@"Create 1k fake threads with 1 message"
actionBlock:^{
[DebugUIMessages createFakeThreads:1000 withFakeMessages:1];
}],
[OWSTableItem itemWithTitle:@"Create 1k fake messages"
actionBlock:^{
[DebugUIMessages sendFakeMessages:1000 thread:thread];