mirror of https://gitee.com/bigwinds/arangodb
all() with skip/limit
This commit is contained in:
parent
9175fddd4d
commit
57aa26bf4a
|
@ -30,7 +30,6 @@
|
|||
|
||||
var console = require("console");
|
||||
var arangodb = require("org/arangodb");
|
||||
var db = arangodb.db;
|
||||
var ArangoCollection = arangodb.ArangoCollection;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -173,6 +172,7 @@ function writeLocked (lockInfo, cb, args) {
|
|||
|
||||
function getLocalDatabases () {
|
||||
var result = { };
|
||||
var db = require("internal").db;
|
||||
|
||||
db._listDatabases().forEach(function (database) {
|
||||
result[database] = { name: database };
|
||||
|
@ -187,6 +187,7 @@ function getLocalDatabases () {
|
|||
|
||||
function getLocalCollections () {
|
||||
var result = { };
|
||||
var db = require("internal").db;
|
||||
|
||||
db._collections().forEach(function (collection) {
|
||||
var name = collection.name();
|
||||
|
@ -226,6 +227,7 @@ function createLocalDatabases (plannedDatabases) {
|
|||
payload);
|
||||
};
|
||||
|
||||
var db = require("internal").db;
|
||||
db._useDatabase("_system");
|
||||
|
||||
var localDatabases = getLocalDatabases();
|
||||
|
@ -282,6 +284,7 @@ function dropLocalDatabases (plannedDatabases) {
|
|||
}
|
||||
};
|
||||
|
||||
var db = require("internal").db;
|
||||
db._useDatabase("_system");
|
||||
|
||||
var localDatabases = getLocalDatabases();
|
||||
|
@ -320,6 +323,7 @@ function cleanupCurrentDatabases () {
|
|||
}
|
||||
};
|
||||
|
||||
var db = require("internal").db;
|
||||
db._useDatabase("_system");
|
||||
|
||||
var all = ArangoAgency.get("Current/Databases", true);
|
||||
|
@ -370,6 +374,7 @@ function createLocalCollections (plannedCollections) {
|
|||
payload);
|
||||
};
|
||||
|
||||
var db = require("internal").db;
|
||||
db._useDatabase("_system");
|
||||
var localDatabases = getLocalDatabases();
|
||||
var database;
|
||||
|
@ -529,6 +534,7 @@ function dropLocalCollections (plannedCollections) {
|
|||
}
|
||||
};
|
||||
|
||||
var db = require("internal").db;
|
||||
db._useDatabase("_system");
|
||||
var shardMap = getShardMap(plannedCollections);
|
||||
|
||||
|
@ -599,6 +605,7 @@ function cleanupCurrentCollections (plannedCollections) {
|
|||
}
|
||||
};
|
||||
|
||||
var db = require("internal").db;
|
||||
db._useDatabase("_system");
|
||||
|
||||
var all = ArangoAgency.get("Current/Collections", true);
|
||||
|
|
|
@ -30,7 +30,6 @@
|
|||
|
||||
var internal = require("internal");
|
||||
var console = require("console");
|
||||
var cluster = require("org/arangodb/cluster");
|
||||
|
||||
var ArangoError = require("org/arangodb").ArangoError;
|
||||
|
||||
|
@ -70,6 +69,7 @@ SimpleQueryAll.prototype.execute = function () {
|
|||
}
|
||||
|
||||
var documents;
|
||||
var cluster = require("org/arangodb/cluster");
|
||||
|
||||
if (cluster.isCoordinator()) {
|
||||
var dbName = require("internal").db._name();
|
||||
|
@ -93,13 +93,40 @@ SimpleQueryAll.prototype.execute = function () {
|
|||
|
||||
var _documents = [ ], total = 0;
|
||||
var result = cluster.wait(coord, shards);
|
||||
var toSkip = this._skip, toLimit = this._limit;
|
||||
|
||||
result.forEach(function(part) {
|
||||
var body = JSON.parse(part.body);
|
||||
_documents = _documents.concat(body.result);
|
||||
total += body.total;
|
||||
|
||||
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, total: total };
|
||||
documents = {
|
||||
documents: _documents,
|
||||
count: _documents.length,
|
||||
total: total
|
||||
};
|
||||
}
|
||||
else {
|
||||
documents = this._collection.ALL(this._skip, this._limit);
|
||||
|
|
Loading…
Reference in New Issue