Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improve performance of loadProtoJSON #1196

Merged
merged 3 commits into from
Mar 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accidentally checked in before. Should remove only

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