mirror of https://gitee.com/bigwinds/arangodb
byExample() sharded
This commit is contained in:
parent
57aa26bf4a
commit
ae05c0c5d3
|
@ -80,6 +80,12 @@ var ArangoDatabase = require("org/arangodb/arango-database").ArangoDatabase;
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
ArangoCollection.prototype.toArray = function () {
|
ArangoCollection.prototype.toArray = function () {
|
||||||
|
var cluster = require("org/arangodb/cluster");
|
||||||
|
|
||||||
|
if (cluster.isCoordinator()) {
|
||||||
|
return this.all().toArray();
|
||||||
|
}
|
||||||
|
|
||||||
return this.ALL(null, null).documents;
|
return this.ALL(null, null).documents;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -76,6 +76,7 @@ SimpleQueryAll.prototype.execute = function () {
|
||||||
var shards = cluster.shardList(dbName, this._collection.name());
|
var shards = cluster.shardList(dbName, this._collection.name());
|
||||||
var coord = { coordTransactionID: ArangoClusterInfo.uniqid() };
|
var coord = { coordTransactionID: ArangoClusterInfo.uniqid() };
|
||||||
var options = { coordTransactionID: coord.coordTransactionID, timeout: 360 };
|
var options = { coordTransactionID: coord.coordTransactionID, timeout: 360 };
|
||||||
|
var limit = this._skip + this._limit;
|
||||||
|
|
||||||
shards.forEach(function (shard) {
|
shards.forEach(function (shard) {
|
||||||
ArangoClusterComm.asyncRequest("put",
|
ArangoClusterComm.asyncRequest("put",
|
||||||
|
@ -85,7 +86,7 @@ SimpleQueryAll.prototype.execute = function () {
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
collection: shard,
|
collection: shard,
|
||||||
skip: 0,
|
skip: 0,
|
||||||
limit: this._skip + this._limit
|
limit: limit || undefined
|
||||||
}),
|
}),
|
||||||
{ },
|
{ },
|
||||||
options);
|
options);
|
||||||
|
@ -305,7 +306,69 @@ SimpleQueryByExample.prototype.execute = function () {
|
||||||
this._skip = 0;
|
this._skip = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var cluster = require("org/arangodb/cluster");
|
||||||
|
|
||||||
|
if (cluster.isCoordinator()) {
|
||||||
|
var dbName = require("internal").db._name();
|
||||||
|
var shards = cluster.shardList(dbName, this._collection.name());
|
||||||
|
var coord = { coordTransactionID: ArangoClusterInfo.uniqid() };
|
||||||
|
var options = { coordTransactionID: coord.coordTransactionID, timeout: 360 };
|
||||||
|
var limit = this._skip + this._limit;
|
||||||
|
var example = this._example;
|
||||||
|
|
||||||
|
shards.forEach(function (shard) {
|
||||||
|
ArangoClusterComm.asyncRequest("put",
|
||||||
|
"shard:" + shard,
|
||||||
|
dbName,
|
||||||
|
"/_api/simple/by-example",
|
||||||
|
JSON.stringify({
|
||||||
|
example: example,
|
||||||
|
collection: shard,
|
||||||
|
skip: 0,
|
||||||
|
limit: limit || undefined
|
||||||
|
}),
|
||||||
|
{ },
|
||||||
|
options);
|
||||||
|
});
|
||||||
|
|
||||||
|
var _documents = [ ];
|
||||||
|
var result = cluster.wait(coord, shards);
|
||||||
|
var toSkip = this._skip, toLimit = this._limit;
|
||||||
|
|
||||||
|
result.forEach(function(part) {
|
||||||
|
var body = JSON.parse(part.body);
|
||||||
|
|
||||||
|
if (toSkip > 0) {
|
||||||
|
if (toSkip >= body.result.length) {
|
||||||
|
toSkip -= body.result.length;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
body.result = body.result.slice(toSkip);
|
||||||
|
toSkip = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (toLimit !== null && toLimit !== undefined) {
|
||||||
|
if (body.result.length >= toLimit) {
|
||||||
|
body.result = body.result.slice(0, toLimit);
|
||||||
|
toLimit = 0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
toLimit -= body.result.length;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_documents = _documents.concat(body.result);
|
||||||
|
});
|
||||||
|
|
||||||
|
documents = {
|
||||||
|
documents: _documents,
|
||||||
|
count: _documents.length
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else {
|
||||||
documents = byExample(this._collection, this._example, this._skip, this._limit);
|
documents = byExample(this._collection, this._example, this._skip, this._limit);
|
||||||
|
}
|
||||||
|
|
||||||
this._execution = new GeneralArrayCursor(documents.documents);
|
this._execution = new GeneralArrayCursor(documents.documents);
|
||||||
this._countQuery = documents.count;
|
this._countQuery = documents.count;
|
||||||
|
|
Loading…
Reference in New Issue