Skip to content

Commit

Permalink
fix: improve performance of loadProtoJSON (#1196)
Browse files Browse the repository at this point in the history
  • Loading branch information
summer-ji-eng authored Mar 4, 2022
1 parent 45ba7dc commit df8eaf9
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/fallback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import {
GoogleAuthOptions,
BaseExternalAccountClient,
} from 'google-auth-library';
import * as objectHash from 'object-hash';
import {OperationsClientBuilder} from './operationsClient';
import {GrpcClientOptions, ClientStubOptions} from './grpc';
import {GaxCall, GRPCCall} from './apitypes';
Expand All @@ -40,6 +39,7 @@ import * as fallbackRest from './fallbackRest';
import {isNodeJS} from './featureDetection';
import {generateServiceStub} from './fallbackServiceStub';
import {StreamType} from '.';
import * as objectHash from 'object-hash';

export {FallbackServiceError};
export {PathTemplate} from './pathTemplate';
Expand Down Expand Up @@ -135,7 +135,7 @@ export class GrpcClient {
}

loadProtoJSON(json: protobuf.INamespace, ignoreCache = false) {
const hash = objectHash(json).toString();
const hash = objectHash(JSON.stringify(json)).toString();
const cached = GrpcClient.protoCache.get(hash);
if (cached && !ignoreCache) {
return cached;
Expand Down
2 changes: 1 addition & 1 deletion src/grpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ export class GrpcClient {
}

loadProtoJSON(json: protobuf.INamespace, ignoreCache = false) {
const hash = objectHash(json).toString();
const hash = objectHash(JSON.stringify(json)).toString();
const cached = GrpcClient.protoCache.get(hash);
if (cached && !ignoreCache) {
return cached;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ describe('v1beta1.EchoClient', () => {
);
});

it.only('invokes echo with closed client', async () => {
it('invokes echo with closed client', async () => {
const client = new echoModule.v1beta1.EchoClient({
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
Expand Down

0 comments on commit df8eaf9

Please sign in to comment.