Skip to content

Commit a2c7987

Browse files
committed
fix: use external parser
1 parent 1e1f769 commit a2c7987

File tree

5 files changed

+32
-159
lines changed

5 files changed

+32
-159
lines changed

package-lock.json

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"@gravity-ui/uikit": "^6.40.0",
2727
"@gravity-ui/websql-autocomplete": "^13.7.0",
2828
"@hookform/resolvers": "^3.10.0",
29+
"@mjackson/multipart-parser": "^0.8.2",
2930
"@reduxjs/toolkit": "^2.5.0",
3031
"@tanstack/react-table": "^8.20.6",
3132
"@ydb-platform/monaco-ghost": "^0.6.1",

src/services/api/streaming.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// eslint-disable-next-line import/no-extraneous-dependencies
2+
import {parseMultipart} from '@mjackson/multipart-parser';
3+
14
import {
25
isQueryResponseChunk,
36
isSessionChunk,
@@ -12,7 +15,6 @@ import type {
1215
StreamingChunk,
1316
} from '../../types/store/streaming';
1417
import {BINARY_DATA_IN_PLAIN_TEXT_DISPLAY} from '../../utils/constants';
15-
import {MultipartStreamParser} from '../parsers/parseMultipartStream';
1618
import {settingsManager} from '../settings';
1719

1820
import {BaseYdbAPI} from './base';
@@ -47,7 +49,7 @@ export class StreamingAPI extends BaseYdbAPI {
4749

4850
let traceId: string | undefined = '';
4951

50-
const streamParser = new MultipartStreamParser((chunk: StreamingChunk) => {
52+
const handleChunk = (chunk: StreamingChunk) => {
5153
if (isSessionChunk(chunk)) {
5254
const sessionChunk = chunk;
5355
sessionChunk.meta.trace_id = traceId;
@@ -57,7 +59,7 @@ export class StreamingAPI extends BaseYdbAPI {
5759
} else if (isQueryResponseChunk(chunk)) {
5860
options.onQueryResponseChunk(chunk);
5961
}
60-
});
62+
};
6163

6264
const queryParams = new URLSearchParams();
6365
// Add only string/number params
@@ -91,19 +93,15 @@ export class StreamingAPI extends BaseYdbAPI {
9193
throw new Error('Empty response body');
9294
}
9395

94-
const reader = response.body.getReader();
9596
traceId = response.headers.get('traceresponse')?.split('-')[1];
9697

97-
try {
98-
for (;;) {
99-
const {done, value} = await reader.read();
100-
if (done) {
101-
break;
102-
}
103-
streamParser.processBuffer(value);
98+
await parseMultipart(response.body, {boundary: 'boundary'}, async (part) => {
99+
try {
100+
const chunk = JSON.parse(await part.text());
101+
handleChunk(chunk);
102+
} catch (e) {
103+
throw new Error(`Error parsing chunk: ${e}`);
104104
}
105-
} finally {
106-
reader.releaseLock();
107-
}
105+
});
108106
}
109107
}

src/services/parsers/parseMultipartStream.ts

Lines changed: 0 additions & 144 deletions
This file was deleted.

src/store/reducers/query/query.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,9 @@ export const queryApi = api.injectEndpoints({
382382
querySettings.tracingLevel && enableTracingLevel
383383
? TracingLevelNumber[querySettings.tracingLevel]
384384
: undefined,
385-
limit_rows: 100000000,
385+
limit_rows: isNumeric(querySettings.limitRows)
386+
? Number(querySettings.limitRows)
387+
: undefined,
386388
transaction_mode:
387389
querySettings.transactionMode === 'implicit'
388390
? undefined

0 commit comments

Comments
 (0)