Skip to content

Commit c13a578

Browse files
committed
fix parser options to workaround stream-json issue
1 parent 5f165a3 commit c13a578

File tree

3 files changed

+30
-31
lines changed

3 files changed

+30
-31
lines changed

perf/results/load.md

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -148,37 +148,15 @@ async function enhancedStreamJson() {
148148

149149
## 4.0.4-load-full-pipeline
150150

151-
- x10: 1574.306ms
152-
- x50: 6226.822ms
153-
- x100: 12414.000ms
151+
- x10: 1784.831ms
152+
- x50: 7229.829ms
153+
- x100: 14543.986ms
154154

155155
```javascript
156-
async function enhancedStreamJson() {
156+
async function loadPipeline() {
157157
const dataStream = fs.createReadStream("./load_data.json");
158-
const streams = [
159-
dataStream,
160-
parser({
161-
packKeys: true,
162-
packStrings: true,
163-
packValues: true,
164-
packNumbers: true,
165-
streamNumbers: false,
166-
streamValues: false,
167-
streamKeys: false,
168-
streamStrings: false
169-
}),
170-
new TransformKeysJsonStream({
171-
getCurrentTransform: buildEntityKeysTransform("camel")
172-
})
173-
];
174-
const asm = Asm.connectTo(streams[streams.length - 1]);
175-
const donePromise = new Promise(resolve => {
176-
asm.on('done', asm => {
177-
resolve(asm.current);
178-
});
179-
});
180-
await StreamUtil.pipelineAsync(streams);
181-
const result = await donePromise;
182-
// console.log(JSON.stringify(result, null, 2));
158+
let body;
159+
const results = await GetDocumentsCommand
160+
.parseDocumentsResultResponseAsync(dataStream, store.conventions, _ => body = _);
183161
}
184162
```

src/Http/RavenCommandResponsePipeline.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,21 @@ export class RavenCommandResponsePipeline<TStreamResult> extends EventEmitter {
166166

167167
if (opts.jsonAsync) {
168168
const parser = new Parser({
169-
packKeys: true
169+
packKeys: true,
170+
packStrings: true,
171+
packNumbers: true,
172+
streamNumbers: true,
173+
streamKeys: false,
174+
streamStrings: false
175+
// TODO perfect setup perf-wise below, reducing traffic by packing all values
176+
// not yet working due to issue uhop/stream-json#44 - stringer freezes
177+
// we still need to stream numbers
178+
// packKeys: true,
179+
// packStrings: true,
180+
// packNumbers: true,
181+
// streamNumbers: false,
182+
// streamKeys: false,
183+
// streamStrings: false
170184
});
171185
streams.push(parser);
172186

test/Mapping/StreamJsonTests.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,14 @@ describe("stream-json parser and stringer", function () {
7373
readable.push(null);
7474

7575
const parser = new Parser({
76-
packKeys: true
76+
packKeys: true,
77+
packStrings: true,
78+
packValues: true,
79+
packNumbers: true,
80+
streamNumbers: true,
81+
streamValues: false,
82+
streamKeys: false,
83+
streamStrings: false
7784
});
7885

7986
const stringerInstance = stringer({ useValues: true });

0 commit comments

Comments
 (0)