Skip to content

Commit

Permalink
fix(perf): disable prettyPrint for slimmer API responses (#860)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenplusplus authored Sep 22, 2020
1 parent 1c54c6a commit 1e56383
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/bigquery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,14 @@ export class BigQuery extends common.Service {
* });
*/
this.getJobsStream = paginator.streamify<Job>('getJobs');

// Disable `prettyPrint` for better performance.
// https://github.com/googleapis/nodejs-bigquery/issues/858
this.interceptors.push({
request: (reqOpts: common.DecorateRequestOptions) => {
return extend(true, {}, reqOpts, {qs: {prettyPrint: false}});
},
});
}

/**
Expand Down
21 changes: 21 additions & 0 deletions test/bigquery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,27 @@ describe('BigQuery', () => {
assert.notDeepStrictEqual(calledWith, options);
assert.deepStrictEqual(calledWith, expectedCalledWith);
});

describe('prettyPrint request interceptor', () => {
let requestInterceptor: Function;

beforeEach(() => {
requestInterceptor = bq.interceptors.pop().request;
});

it('should disable prettyPrint', () => {
assert.deepStrictEqual(requestInterceptor({}), {
qs: {prettyPrint: false},
});
});

it('should clone json', () => {
const reqOpts = {qs: {a: 'b'}};
const expectedReqOpts = {qs: {a: 'b', prettyPrint: false}};
assert.deepStrictEqual(requestInterceptor(reqOpts), expectedReqOpts);
assert.notDeepStrictEqual(reqOpts, expectedReqOpts);
});
});
});

describe('mergeSchemaWithRows_', () => {
Expand Down

0 comments on commit 1e56383

Please sign in to comment.