Skip to content

Commit a2a25c6

Browse files
committed
refactor: implement lazy initialization for GitHub executor singleton
1 parent 6570de0 commit a2a25c6

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

lib/github.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -697,10 +697,18 @@ function createDefaultGitHubExecutor(): GitHubQueryExecutor {
697697
});
698698
}
699699

700-
const executorSingleton = createDefaultGitHubExecutor();
700+
let executorSingleton: GitHubQueryExecutor | undefined;
701701
const cacheConfigSingleton = getCacheConfigFromEnv();
702702
const cacheStoreSingleton = createCacheStore(cacheConfigSingleton);
703703

704+
function getDefaultGitHubExecutor(): GitHubQueryExecutor {
705+
if (!executorSingleton) {
706+
executorSingleton = createDefaultGitHubExecutor();
707+
}
708+
709+
return executorSingleton;
710+
}
711+
704712
/**
705713
* Redis cache entry shape that includes a fetch timestamp for staleness checks.
706714
*/
@@ -811,7 +819,10 @@ export async function getUserData(
811819
}
812820

813821
// ── 3. Fetch from GitHub API ──────────────────────────────────────────
814-
const { data: fresh, metrics } = await fetchUserDataFromGitHub(executorSingleton, normalizedUsername);
822+
const { data: fresh, metrics } = await fetchUserDataFromGitHub(
823+
getDefaultGitHubExecutor(),
824+
normalizedUsername,
825+
);
815826

816827
// Upsert into PostgreSQL
817828
try {

0 commit comments

Comments
 (0)