diff --git a/js/client/client.js b/js/client/client.js index e7bd21c445..6e1e5ac1ca 100755 --- a/js/client/client.js +++ b/js/client/client.js @@ -1648,10 +1648,17 @@ function ArangoCollection (database, data) { if (limit === null) { if (probability >= 1.0) { - stmt = internal.sprintf("FOR d IN %s RETURN d", this.name()); + cursor = this.all(); } else { stmt = internal.sprintf("FOR d IN %s FILTER rand() >= @prob RETURN d", this.name()); + stmt = internal.db._createStatement({ query: stmt }); + + if (probability < 1.0) { + stmt.bind("prob", probability); + } + + cursor = stmt.execute(); } } else { @@ -1664,21 +1671,21 @@ function ArangoCollection (database, data) { } if (probability >= 1.0) { - stmt = internal.sprintf("FOR d IN %s LIMIT %d RETURN d", this.name(), limit); + cursor = this.all().limit(limit); } else { stmt = internal.sprintf("FOR d IN %s FILTER rand() >= @prob LIMIT %d RETURN d", this.name(), limit); + stmt = internal.db._createStatement({ query: stmt }); + + if (probability < 1.0) { + stmt.bind("prob", probability); + } + + cursor = stmt.execute(); } } - stmt = internal.db._createStatement({ query: stmt, batchSize: 100 }); - - if (probability < 1.0) { - stmt.bind("prob", probability); - } - - cursor = stmt.execute(); pos = 0; while (cursor.hasNext()) { diff --git a/js/server/ArangoCollection.js b/js/server/ArangoCollection.js index 36c21c42df..876281a2f7 100644 --- a/js/server/ArangoCollection.js +++ b/js/server/ArangoCollection.js @@ -249,10 +249,17 @@ if (limit === null) { if (probability >= 1.0) { - stmt = internal.sprintf("FOR d IN %s RETURN d", this.name()); + cursor = this.all(); } else { stmt = internal.sprintf("FOR d IN %s FILTER rand() >= @prob RETURN d", this.name()); + stmt = internal.db._createStatement({ query: stmt }); + + if (probability < 1.0) { + stmt.bind("prob", probability); + } + + cursor = stmt.execute(); } } else { @@ -265,21 +272,21 @@ } if (probability >= 1.0) { - stmt = internal.sprintf("FOR d IN %s LIMIT %d RETURN d", this.name(), limit); + cursor = this.all().limit(limit); } else { stmt = internal.sprintf("FOR d IN %s FILTER rand() >= @prob LIMIT %d RETURN d", this.name(), limit); + stmt = internal.db._createStatement({ query: stmt }); + + if (probability < 1.0) { + stmt.bind("prob", probability); + } + + cursor = stmt.execute(); } } - stmt = internal.db._createStatement({ query: stmt }); - - if (probability < 1.0) { - stmt.bind("prob", probability); - } - - cursor = stmt.execute(); pos = 0; while (cursor.hasNext()) {