mongodb-explain-compat 3.1.0 → 3.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/index.js +41 -17
  2. package/package.json +3 -8
package/lib/index.js CHANGED
@@ -5,19 +5,41 @@ const kSBENodes = Symbol('kSBENodes');
5
5
  function mapPlanTree(stage, mapper, currentParent = null) {
6
6
  const result = mapper(stage, currentParent);
7
7
  const target = result || {};
8
- if (stage.inputStage) target.inputStage = mapPlanTree(stage.inputStage, mapper, stage);
9
- if (stage.innerStage) target.innerStage = mapPlanTree(stage.innerStage, mapper, stage);
10
- if (stage.outerStage) target.outerStage = mapPlanTree(stage.outerStage, mapper, stage);
11
- if (stage.thenStage) target.thenStage = mapPlanTree(stage.thenStage, mapper, stage);
12
- if (stage.elseStage) target.elseStage = mapPlanTree(stage.elseStage, mapper, stage);
13
- if (stage.inputStages) target.inputStages = stage.inputStages.map(s => mapPlanTree(s, mapper, stage));
14
- if (stage.shards) target.shards = stage.shards.map(s => mapPlanTree(s, stage));
15
- if (stage.executionStages) target.executionStages = stage.executionStages.map(s => mapPlanTree(s, mapper, stage));
8
+ if (stage.inputStage) {
9
+ target.inputStage = mapPlanTree(stage.inputStage, mapper, stage);
10
+ }
11
+ if (stage.innerStage) {
12
+ target.innerStage = mapPlanTree(stage.innerStage, mapper, stage);
13
+ }
14
+ if (stage.outerStage) {
15
+ target.outerStage = mapPlanTree(stage.outerStage, mapper, stage);
16
+ }
17
+ if (stage.thenStage) {
18
+ target.thenStage = mapPlanTree(stage.thenStage, mapper, stage);
19
+ }
20
+ if (stage.elseStage) {
21
+ target.elseStage = mapPlanTree(stage.elseStage, mapper, stage);
22
+ }
23
+ if (stage.inputStages) {
24
+ target.inputStages = stage.inputStages.map((s) =>
25
+ mapPlanTree(s, mapper, stage)
26
+ );
27
+ }
28
+ if (stage.shards) {
29
+ target.shards = stage.shards.map((s) => mapPlanTree(s, stage));
30
+ }
31
+ if (stage.executionStages) {
32
+ target.executionStages = stage.executionStages.map((s) =>
33
+ mapPlanTree(s, mapper, stage)
34
+ );
35
+ }
16
36
  return result;
17
37
  }
18
38
 
19
39
  function omitChildStages(stage) {
20
- return mapPlanTree(stage, child => stage === child ? { ...stage } : undefined);
40
+ return mapPlanTree(stage, (child) =>
41
+ stage === child ? { ...stage } : undefined
42
+ );
21
43
  }
22
44
 
23
45
  function mapStages(queryPlan, sbeExecutionStages) {
@@ -25,7 +47,7 @@ function mapStages(queryPlan, sbeExecutionStages) {
25
47
 
26
48
  // First, look up all stages from the query plan, and store their IDs so
27
49
  // that we know which SBE nodes we should assign to which query plan node.
28
- mapPlanTree(queryPlan, stage => {
50
+ mapPlanTree(queryPlan, (stage) => {
29
51
  if (stage.planNodeId) {
30
52
  nodeIdToQueryPlan.set(stage.planNodeId, stage);
31
53
  stage[kSBENodes] = [];
@@ -53,21 +75,23 @@ function mapStages(queryPlan, sbeExecutionStages) {
53
75
  // Do the actual mapping here. Use the head SBE node, and only aggregate
54
76
  // 'docsExamined' based on all child nodes and 'executionTimeMillisEstimate'
55
77
  // based on all top-level child nodes here.
56
- return mapPlanTree(queryPlan, stage => {
78
+ return mapPlanTree(queryPlan, (stage) => {
57
79
  const sbeNodes = stage[kSBENodes];
58
80
  const headSBENode = sbeNodes[0] || {};
59
81
  return {
60
82
  ...omitChildStages(headSBENode),
61
83
  ...omitChildStages(stage),
62
- executionTimeMillisEstimate: headSBENode.executionTimeMillis || headSBENode.executionTimeMillisEstimate,
84
+ executionTimeMillisEstimate:
85
+ headSBENode.executionTimeMillis ||
86
+ headSBENode.executionTimeMillisEstimate,
63
87
  docsExamined: sbeNodes
64
- .filter(sbe => sbe.stage === 'seek' || sbe.stage === 'scan')
65
- .map(sbe => sbe.numReads || 0)
88
+ .filter((sbe) => sbe.stage === 'seek' || sbe.stage === 'scan')
89
+ .map((sbe) => sbe.numReads || 0)
66
90
  .reduce((a, b) => a + b, 0),
67
91
  keysExamined: sbeNodes
68
- .filter(sbe => sbe.stage === 'ixseek' || sbe.stage === 'ixscan')
69
- .map(sbe => sbe.numReads || 0)
70
- .reduce((a, b) => a + b, 0)
92
+ .filter((sbe) => sbe.stage === 'ixseek' || sbe.stage === 'ixscan')
93
+ .map((sbe) => sbe.numReads || 0)
94
+ .reduce((a, b) => a + b, 0),
71
95
  };
72
96
  });
73
97
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mongodb-explain-compat",
3
- "version": "3.1.0",
3
+ "version": "3.1.2",
4
4
  "description": "Convert mongodb SBE explain output to 4.4 explain output",
5
5
  "keywords": [
6
6
  "mongodb",
@@ -47,16 +47,11 @@
47
47
  },
48
48
  "license": "SSPL",
49
49
  "devDependencies": {
50
+ "@mongodb-js/eslint-config-compass": "^1.1.8",
50
51
  "eslint": "^7.25.0",
51
- "eslint-config-semistandard": "^15.0.1",
52
- "eslint-config-standard": "^14.1.1",
53
- "eslint-plugin-import": "^2.22.0",
54
- "eslint-plugin-node": "^11.1.0",
55
- "eslint-plugin-promise": "^4.2.1",
56
- "eslint-plugin-standard": "^4.0.1",
57
52
  "gen-esm-wrapper": "^1.1.0",
58
53
  "mocha": "^10.2.0",
59
54
  "nyc": "^15.1.0"
60
55
  },
61
- "gitHead": "36ab9850539afa17c602487d440cdfa07bade181"
56
+ "gitHead": "798e37090869e6008399cbb9ee399b3f3f4dd86e"
62
57
  }