无法在云数据库中更快地获取数据
Unable to fetch data faster in cloudant DB
我正在为我的 iOS 应用程序使用 cloud ant Db,名称为 tasks_master
,包含近 1000 个文档。当我尝试从云蚂蚁获取数据时,我用下面的代码尝试了将近 30 秒来获取数据。
- (NSURL*) replicatorURL {
AppDelegate *app = [[UIApplication sharedApplication]delegate];
NSString *db_name = @"tasks_master";
NSString *url = [NSString stringWithFormat:@"https://%@:%@@%@.cloudant.com/%@",
username,
password,
username,db_name];
return [NSURL URLWithString:url];
}
- (void) sync:(UIViewController *)sender {
[self pullReplication:sender];
[self pushReplication:sender];
}
-(void)pullReplication:(UIViewController *)sender {
[self log:@"Starting pull replication"];
NSURL *url = [self replicatorURL];
AppDelegate *delegate1 = (AppDelegate *)[[UIApplication sharedApplication] delegate];
CDTReplicatorFactory *factory = delegate1.replicatorFactory;
CDTReplicator *replicator = [factory onewaySourceURI:url targetDatastore:delegate1.datastore];
[self startAndFollowReplicator:replicator label:@"pull"];
}
- (void) pushReplication:(UIViewController *)sender {
[self log:@"Starting push replication"];
NSURL *url = [self replicatorURL];
AppDelegate *delegate1 = (AppDelegate *)[[UIApplication sharedApplication] delegate];
CDTReplicatorFactory *factory = delegate1.replicatorFactory;
CDTReplicator *replicator = [factory onewaySourceDatastore:delegate1.datastore targetURI:url];
[self startAndFollowReplicator:replicator label:@"push"];
}
当我调用任务时
-(void)fetchtasks{
[[[CDTTodoReplicator alloc]init]sync];
self.indexManager = [[CDTIndexManager alloc] initWithDatastore:self.datastore
error:&error];
indexName= [self.datastore ensureIndexed:@[@"originator",@"members",@"meeting_status"] withName:@"meeting_index"];
query=@{@"$and":@[@{@"meeting_status":@"Scheduled"}, @{@"$or":@[@{@"originator":app.userName},@{@"members":app.userName}]}]};
result = [self.datastore find:query];
}
任何人都可以帮助我如何更快地获取数据。
我写了一个小帮手 class 来减少这类事情的一些样板。这是上面引用的视频中使用的那个。
Cloudant.h https://gist.github.com/xpqz/f8b304353080c3963a45
Cloudant.m https://gist.github.com/xpqz/62b5267c250f04c30f9b
当您将文档添加到 Cloudant 数据库时,它们将通过所谓的主索引(也称为 All Docs)变得可用。这可以很容易地从命令行使用 'curl' 检查,例如:
% curl https://skruger.cloudant.com/routes/_all_docs
您存储的每个文档都会出现在主索引返回的数据中。
设计文档用于不同的目的 - 它们定义二级索引,称为视图,主要编写为小 javascript 函数,定义 map-reduce 操作以公开数据的某些方面。视图允许您以其他方式将您的文档索引到您免费获得的文档 ID。
您可以通过自己创建设计文档来直接创建自己的视图,但是访问数据库的客户端软件有时也会自动创建设计文档和视图,当您在 _design 下看到您没有明确显示的内容时,有时会感到困惑创建。
总结:每个文档都出现在主索引中,_all_docs。设计文档包含 javascript 用于生成二级索引(称为视图)的函数。这些可以显式创建,或由客户端软件自动生成 'behind your back'。
更多信息:
斯蒂芬
我正在为我的 iOS 应用程序使用 cloud ant Db,名称为 tasks_master
,包含近 1000 个文档。当我尝试从云蚂蚁获取数据时,我用下面的代码尝试了将近 30 秒来获取数据。
- (NSURL*) replicatorURL {
AppDelegate *app = [[UIApplication sharedApplication]delegate];
NSString *db_name = @"tasks_master";
NSString *url = [NSString stringWithFormat:@"https://%@:%@@%@.cloudant.com/%@",
username,
password,
username,db_name];
return [NSURL URLWithString:url];
}
- (void) sync:(UIViewController *)sender {
[self pullReplication:sender];
[self pushReplication:sender];
}
-(void)pullReplication:(UIViewController *)sender {
[self log:@"Starting pull replication"];
NSURL *url = [self replicatorURL];
AppDelegate *delegate1 = (AppDelegate *)[[UIApplication sharedApplication] delegate];
CDTReplicatorFactory *factory = delegate1.replicatorFactory;
CDTReplicator *replicator = [factory onewaySourceURI:url targetDatastore:delegate1.datastore];
[self startAndFollowReplicator:replicator label:@"pull"];
}
- (void) pushReplication:(UIViewController *)sender {
[self log:@"Starting push replication"];
NSURL *url = [self replicatorURL];
AppDelegate *delegate1 = (AppDelegate *)[[UIApplication sharedApplication] delegate];
CDTReplicatorFactory *factory = delegate1.replicatorFactory;
CDTReplicator *replicator = [factory onewaySourceDatastore:delegate1.datastore targetURI:url];
[self startAndFollowReplicator:replicator label:@"push"];
}
当我调用任务时
-(void)fetchtasks{
[[[CDTTodoReplicator alloc]init]sync];
self.indexManager = [[CDTIndexManager alloc] initWithDatastore:self.datastore
error:&error];
indexName= [self.datastore ensureIndexed:@[@"originator",@"members",@"meeting_status"] withName:@"meeting_index"];
query=@{@"$and":@[@{@"meeting_status":@"Scheduled"}, @{@"$or":@[@{@"originator":app.userName},@{@"members":app.userName}]}]};
result = [self.datastore find:query];
}
任何人都可以帮助我如何更快地获取数据。
我写了一个小帮手 class 来减少这类事情的一些样板。这是上面引用的视频中使用的那个。
Cloudant.h https://gist.github.com/xpqz/f8b304353080c3963a45
Cloudant.m https://gist.github.com/xpqz/62b5267c250f04c30f9b
当您将文档添加到 Cloudant 数据库时,它们将通过所谓的主索引(也称为 All Docs)变得可用。这可以很容易地从命令行使用 'curl' 检查,例如:
% curl https://skruger.cloudant.com/routes/_all_docs
您存储的每个文档都会出现在主索引返回的数据中。
设计文档用于不同的目的 - 它们定义二级索引,称为视图,主要编写为小 javascript 函数,定义 map-reduce 操作以公开数据的某些方面。视图允许您以其他方式将您的文档索引到您免费获得的文档 ID。
您可以通过自己创建设计文档来直接创建自己的视图,但是访问数据库的客户端软件有时也会自动创建设计文档和视图,当您在 _design 下看到您没有明确显示的内容时,有时会感到困惑创建。
总结:每个文档都出现在主索引中,_all_docs。设计文档包含 javascript 用于生成二级索引(称为视图)的函数。这些可以显式创建,或由客户端软件自动生成 'behind your back'。
更多信息:
斯蒂芬