Skip to content

Instantly share code, notes, and snippets.

@kurorido
Last active August 29, 2015 14:03
Show Gist options
  • Select an option

  • Save kurorido/18e93d178a471a128bca to your computer and use it in GitHub Desktop.

Select an option

Save kurorido/18e93d178a471a128bca to your computer and use it in GitHub Desktop.
test Query CouchBase With View And Stale False
void testQueryCouchBaseWithViewAndStaleFalse() {
print("Testing Query CouchBase with View...");
CouchClient _dbclient;
CouchClient.connect([Uri.parse("http://10.1.4.112:8091/pools")], "default", "").then((CouchClient c) {
_dbclient = c;
}).then((_) {
int startTime = new DateTime.now().millisecondsSinceEpoch;
List<Future> futures = new List();
int count = 0;
// 20(get) : 1(view)
for (var i = 0; i < 1000000; i++) {
if(count == 20) {
_dbclient.getView("foo", "by_bar").then((view){
Query query = new Query();
query.key = i.toString();
query.stale = Stale.FALSE;
query.includeDocs = false;
futures.add(_dbclient.query(view, query));
});
} else {
futures.add(_dbclient.get(i.toString()));
}
if(i % 20 == 0) {
count = 0;
} else {
count++;
}
}
return Future.wait(futures).then((_) {
int endTime = new DateTime.now().millisecondsSinceEpoch;
int timeCost = endTime - startTime;
print(timeCost.toString() + "ms"); // 409620ms
// if I all query by view: 9581ms
}).whenComplete(() {
_dbclient.close();
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment