CBLDatabase *database = [[CBLManager sharedInstance] databaseNamed:@"test" error:nil];
CBLView *v1 = [database viewNamed:viewName];
[v1 setMapBlock:MAPBLOCK({emit (nil, doc[kDocumentID]);}) version:@"1.0"];
CBLQuery *q1 = [v1 createQuery];
CBLQueryEnumerator *enumerator = [q1 run:nil];
NSMutableArray *documentIDs = [NSMutableArray array];
CBLQueryRow *row = nil;
while ((row = [enumerator nextRow]) != nil)
{
id documentID = [row value];
[documentIDs addObject:documentID];
}
double beforeSingleFetch = [NSDate timeIntervalSinceReferenceDate];
NSMutableArray *singleFetch = [NSMutableArray array];
for (NSString *documentID in documentIDs)
{
CBLDocument *singleFetchDocument = [database documentWithID:documentID];
[singleFetch addObject:singleFetchDocument];
}
double afterSingleFetch = [NSDate timeIntervalSinceReferenceDate];
double singleFetchDuration = afterSingleFetch - beforeSingleFetch;
double beforeBulkFetch = [NSDate timeIntervalSinceReferenceDate];
NSMutableArray *bulkFetch = [NSMutableArray array];
[database inTransaction:^BOOL{
for (NSString *documentID in documentIDs)
{
CBLDocument *bulkFetchDocument = [database documentWithID:documentID];
[bulkFetch addObject:bulkFetchDocument];
}
return YES;
}];
double afterBulkFetch = [NSDate timeIntervalSinceReferenceDate];
double bulkFetchDuration = afterBulkFetch - beforeBulkFetch;
NSAssert(singleFetchDuration > bulkFetchDuration, @"A bulk fetch should be faster!");
On Oct 28, 2014, at 3:10 AM, Alexander Selling <alexande...@gmail.com> wrote:I understand that the test is super naive, there's caching involved that would render the test useless. However, does cbl do bulk fetches? Is that what a transaction is for in this case?