Skip to content

Commit 8fee0dd

Browse files
decyjphrCopilot
andcommitted
perf: cache enterprise installation ID to avoid repeated lookups
Store the enterprise installation ID after the first successful lookup so subsequent calls to enrichContextWithEnterprise can skip the listInstallations API call and directly call robot.auth(cachedId). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent a51ab87 commit 8fee0dd

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ let deploymentConfig
1212

1313
module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) => {
1414
let appSlug = 'safe-settings'
15+
let cachedEnterpriseInstallationId = null
1516
async function syncAllSettings (nop, context, repo = context.repo(), ref, baseRef, changedFiles = {}) {
1617
try {
1718
deploymentConfig = await loadYamlFileSystem()
@@ -159,6 +160,12 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) =>
159160
if (enterprise && enterprise.slug) {
160161
context.enterpriseSlug = enterprise.slug
161162
try {
163+
// Use cached enterprise installation ID if available
164+
if (cachedEnterpriseInstallationId) {
165+
context.appGithub = await robot.auth(cachedEnterpriseInstallationId)
166+
return
167+
}
168+
162169
// Get a JWT-authenticated client to list all installations
163170
const appGithub = await robot.auth()
164171
const installations = await appGithub.paginate(
@@ -169,7 +176,8 @@ module.exports = (robot, { getRouter }, Settings = require('./lib/settings')) =>
169176
i => i.target_type === 'Enterprise' && i.account && i.account.slug === enterprise.slug
170177
)
171178
if (enterpriseInstallation) {
172-
context.appGithub = await robot.auth(enterpriseInstallation.id)
179+
cachedEnterpriseInstallationId = enterpriseInstallation.id
180+
context.appGithub = await robot.auth(cachedEnterpriseInstallationId)
173181
} else {
174182
robot.log.debug(`No enterprise installation found for slug '${enterprise.slug}'. App installation management will not be available.`)
175183
}

0 commit comments

Comments
 (0)