8000 Move roundCost function to utilities (#9247) · reynoldsm88/arangodb@a793f72 · GitHub
[go: up one dir, main page]

Skip to content

Commit a793f72

Browse files
markuspfmchacki
authored andcommitted
Move roundCost function to utilities (arangodb#9247)
1 parent 1982a55 commit a793f72

File tree

2 files changed

+24
-21
lines changed

2 files changed

+24
-21
lines changed

js/server/modules/@arangodb/aql-helper.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,27 @@ function removeClusterNodesFromPlan (nodes) {
381381
});
382382
}
383383

384+
function roundCost (obj) {
385+
if (Array.isArray(obj)) {
386+
return obj.map(roundCost);
387+
} else if (typeof obj === 'object') {
388+
var result = {};
389+
for (var key in obj) {
390+
if (obj.hasOwnProperty(key)) {
391+
if (key === "estimatedCost" ) {
392+
result[key] = Math.round(obj[key]);
393+
} else {
394+
result[key] = roundCost(obj[key]);
395+
}
396+
}
397+
}
398+
return result;
399+
} else {
400+
return obj;
401+
}
402+
}
403+
404+
384405
exports.getParseResults = getParseResults;
385406
exports.assertParseError = assertParseError;
386407
exports.getQueryExplanation = getQueryExplanation;
@@ -398,3 +419,4 @@ exports.getQueryMultiplePlansAndExecutions = getQueryMultiplePlansAndExecutions;
398419
exports.removeAlwaysOnClusterRules = removeAlwaysOnClusterRules;
399420
exports.removeClusterNodes = removeClusterNodes;
400421
exports.removeClusterNodesFromPlan = removeClusterNodesFromPlan;
422+
exports.roundCost = roundCost;

tests/js/server/aql/aql-graph-traverser.js

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -39,34 +39,15 @@ const gm = require('@arangodb/general-graph');
3939
const vn = 'UnitTestVertexCollection';
4040
const en = 'UnitTestEdgeCollection';
4141
const isCluster = require('@arangodb/cluster').isCluster();
42+
const roundCost = require('@arangodb/aql-helper').roundCost;
43+
4244
var _ = require('lodash');
4345
var vertex = {};
4446
var edge = {};
4547
var vc;
4648
var ec;
4749
var mmfilesEngine = (db._engine().name === 'mmfiles');
4850

49-
50-
let roundCost = function(obj) {
51-
if (Array.isArray(obj)) {
52-
return obj.map(roundCost);
53-
} else if (typeof obj === 'object') {
54-
var result = {};
55-
for (var key in obj) {
56-
if (obj.hasOwnProperty(key)) {
57-
if (key === "estimatedCost" ) {
58-
result[key] = Math.round(obj[key]);
59-
} else {
60-
result[key] = roundCost(obj[key]);
61-
}
62-
}
63-
}
64-
return result;
65-
} else {
66-
return obj;
67-
}
68-
};
69-
7051
var cleanup = function () {
7152
db._drop(vn);
7253
db._drop(en);

0 commit comments

Comments
 (0)
0