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 <mtlewis@users.noreply.github.com>
This commit is contained in:
MT Lewis
2026-05-19 13:56:52 +01:00
parent 91d7d91317
commit 253c014cc1
2 changed files with 12 additions and 3 deletions
@@ -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<boolean> {
if (!this.useRestSuspendedCheck) {
return false;
}
const restClient = this.getRestClient(org);
return (
(await isGitHubEnterprise(restClient)) &&
(await this.isGitHubEnterprise(org)) &&
(await isSuspended(login, restClient, { org }))
);
}
@@ -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 }))
);
}