Skip to content

Commit 083b977

Browse files
committed
fix: better code
1 parent b7f19aa commit 083b977

File tree

2 files changed

+7
-16
lines changed

2 files changed

+7
-16
lines changed

src/services/api/streaming.ts

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// eslint-disable-next-line import/no-extraneous-dependencies
22
import {parseMultipart} from '@mjackson/multipart-parser';
3+
import qs from 'qs';
34

45
import {
56
isQueryResponseChunk,
@@ -14,6 +15,8 @@ import {settingsManager} from '../settings';
1415

1516
import {BaseYdbAPI} from './base';
1617

18+
const BOUNDARY = 'boundary';
19+
1720
export interface StreamQueryParams {
1821
query?: string;
1922
database?: string;
@@ -42,17 +45,7 @@ export class StreamingAPI extends BaseYdbAPI {
4245
true,
4346
);
4447

45-
let traceId: string | undefined = '';
46-
47-
const queryParams = new URLSearchParams();
48-
// Add only string/number params
49-
Object.entries(params).forEach(([key, value]) => {
50-
if (value !== undefined) {
51-
queryParams.set(key, String(value));
52-
}
53-
});
54-
queryParams.set('base64', String(base64));
55-
queryParams.set('schema', 'multipart');
48+
const queryParams = qs.stringify({...params, base64}, {encoder: encodeURIComponent});
5649

5750
const headers = new Headers({
5851
Accept: 'multipart/x-mixed-replace',
@@ -76,9 +69,9 @@ export class StreamingAPI extends BaseYdbAPI {
7669
throw new Error('Empty response body');
7770
}
7871

79-
traceId = response.headers.get('traceresponse')?.split('-')[1];
72+
const traceId = response.headers.get('traceresponse')?.split('-')[1];
8073

81-
await parseMultipart(response.body, {boundary: 'boundary'}, async (part) => {
74+
await parseMultipart(response.body, {boundary: BOUNDARY}, async (part) => {
8275
try {
8376
const chunk = JSON.parse(await part.text());
8477

src/store/reducers/query/query.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* eslint-disable complexity */
2-
/* eslint-disable no-param-reassign */
31
import {createSlice} from '@reduxjs/toolkit';
42
import type {PayloadAction} from '@reduxjs/toolkit';
53

@@ -287,7 +285,6 @@ export const queryApi = api.injectEndpoints({
287285
},
288286
{signal, dispatch},
289287
) => {
290-
const timeStart = Date.now();
291288
dispatch(setQueryResult({type: actionType, queryId, isLoading: true}));
292289

293290
const {action, syntax} = getActionAndSyntaxFromQueryMode(
@@ -296,6 +293,7 @@ export const queryApi = api.injectEndpoints({
296293
);
297294

298295
try {
296+
const timeStart = Date.now();
299297
const response = await window.api.viewer.sendQuery(
300298
{
301299
query,

0 commit comments

Comments
 (0)