New to Couchbase Lite iOS and have 350,000 documents in a bucket. These are split into 4 main categories:
- Locations (60k)
- Dogs (185k)
- Cats (50k)
- Owners (35k)
I'm having real problems with view speed, firstly trying to grab close locations will take 30 seconds for the first query, and subsequent ones are fast. However, we can't have the user waiting 30 seconds as the app loads! The code for this is below:
double lat = 51.504656;
double lon = -0.128299;
CBLView * view = [self.database viewNamed:@"close"];
[view setMapBlock: MAPBLOCK({
if ([doc[@"type"] isEqualToString:@"location"]) {
emit(CBLGeoPointKey([doc[@"lat"] doubleValue], [doc[@"lon"] doubleValue]), doc[@"name"]);
}
}) version: @"0.0.1"];
CBLQuery * query = [[self.database viewNamed:@"close"] createQuery];
query.boundingBox = (CBLGeoRect){{lat - .005, lon - .005}, {lat + .005, lon + .005}};;
query.limit = 10;
CBLQueryEnumerator * rowEnum = [query run:&error];
for (CBLGeoQueryRow * row in rowEnum) {
NSLog(@"%@", row.document[@"name"]);
}
I'm not sure how I can make this any faster. I've tried changing the indexUpdateMode to "after", but that didn't make any difference.
Also, a quick sub-question: I assume most of the time is from indexing the database (since subsequent queries are fast), is there any way to automatically index the database as soon as it is synced?