From 253c014cc1f1ff78d3a8b8ef0e370610928f2f31 Mon Sep 17 00:00:00 2001 From: MT Lewis Date: Tue, 19 May 2026 13:56:52 +0100 Subject: [PATCH] feat(catalog-backend-module-github): memoize isGitHubEnterprise check We should mostly get these for free because of the GitHub conditional request caching, but this is a nice safety net and also probably saves us some time. Signed-off-by: MT Lewis --- .../src/providers/GithubMultiOrgEntityProvider.ts | 8 ++++++-- .../src/providers/GithubOrgEntityProvider.ts | 7 ++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/plugins/catalog-backend-module-github/src/providers/GithubMultiOrgEntityProvider.ts b/plugins/catalog-backend-module-github/src/providers/GithubMultiOrgEntityProvider.ts index 9b0a622d9f..21308a6452 100644 --- a/plugins/catalog-backend-module-github/src/providers/GithubMultiOrgEntityProvider.ts +++ b/plugins/catalog-backend-module-github/src/providers/GithubMultiOrgEntityProvider.ts @@ -52,7 +52,7 @@ import { TeamEditedEvent, TeamEvent, } from '@octokit/webhooks-types'; -import { merge } from 'lodash'; +import { memoize, merge } from 'lodash'; import { randomUUID } from 'node:crypto'; import { @@ -315,13 +315,17 @@ export class GithubMultiOrgEntityProvider implements EntityProvider { return client; } + private isGitHubEnterprise = memoize((org: string) => + isGitHubEnterprise(this.getRestClient(org)), + ); + private async shouldExclude(login: string, org: string): Promise { if (!this.useRestSuspendedCheck) { return false; } const restClient = this.getRestClient(org); return ( - (await isGitHubEnterprise(restClient)) && + (await this.isGitHubEnterprise(org)) && (await isSuspended(login, restClient, { org })) ); } diff --git a/plugins/catalog-backend-module-github/src/providers/GithubOrgEntityProvider.ts b/plugins/catalog-backend-module-github/src/providers/GithubOrgEntityProvider.ts index d94d5c3bd5..9e62a87a99 100644 --- a/plugins/catalog-backend-module-github/src/providers/GithubOrgEntityProvider.ts +++ b/plugins/catalog-backend-module-github/src/providers/GithubOrgEntityProvider.ts @@ -75,6 +75,7 @@ import { } from '../lib/org'; import { parseGithubOrgUrl } from '../lib/util'; import { withLocations } from '../lib/withLocations'; +import { memoize } from 'lodash'; const EVENT_TOPICS = [ 'github.membership', @@ -260,6 +261,10 @@ export class GithubOrgEntityProvider implements EntityProvider { ); } + private isGitHubEnterprise = memoize(() => + isGitHubEnterprise(this.getRestClient()), + ); + private getRestClient(): Octokit { if (!this.cachedRestClient) { this.cachedRestClient = createRestClient({ @@ -279,7 +284,7 @@ export class GithubOrgEntityProvider implements EntityProvider { } const restClient = this.getRestClient(); return ( - (await isGitHubEnterprise(restClient)) && + (await this.isGitHubEnterprise()) && (await isSuspended(login, restClient, { org })) ); }