Skip to content

Commit 3887115

Browse files
authored
perf(config): use minimal accounts query when resolving configuration (#6184)
1 parent aab5b2d commit 3887115

File tree

2 files changed

+43
-10
lines changed

2 files changed

+43
-10
lines changed

packages/config/src/api/site_info.ts

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,12 @@ export const getSiteInfo = async function ({
7474
return { siteInfo, accounts: [], addons: [], integrations }
7575
}
7676

77-
const promises = [
77+
const [siteInfo, accounts, addons, integrations] = await Promise.all([
7878
getSite(api, siteId, siteFeatureFlagPrefix),
7979
getAccounts(api),
8080
getAddons(api, siteId),
8181
getIntegrations({ siteId, testOpts, offline, accountId, token, featureFlags, extensionApiBaseUrl, mode }),
82-
]
83-
84-
const [siteInfo, accounts, addons, integrations] = await Promise.all(promises)
82+
])
8583

8684
if (siteInfo.use_envelope) {
8785
const envelope = await getEnvelope({ api, accountId: siteInfo.account_slug, siteId, context })
@@ -105,12 +103,28 @@ const getSite = async function (api: NetlifyAPI, siteId: string, siteFeatureFlag
105103
}
106104
}
107105

108-
const getAccounts = async function (api: NetlifyAPI) {
106+
export type MinimalAccount = {
107+
id: string
108+
name: string
109+
slug: string
110+
default: boolean
111+
team_logo_url: string | null
112+
on_pro_trial: boolean
113+
organization_id: string | null
114+
type_name: string
115+
type_slug: string
116+
members_count: number
117+
}
118+
119+
const getAccounts = async function (api: NetlifyAPI): Promise<MinimalAccount[]> {
109120
try {
110-
const accounts = await (api as any).listAccountsForUser()
111-
return Array.isArray(accounts) ? accounts : []
121+
const accounts = (await api.listAccountsForUser(
122+
// @ts-expect-error(ndhoule): This is an unpublished, internal querystring parameter
123+
{ minimal: 'true' },
124+
)) as MinimalAccount[] | null
125+
return Array.isArray(accounts) ? (accounts as MinimalAccount[]) : []
112126
} catch (error) {
113-
throwUserError(`Failed retrieving user account: ${error.message}. ${ERROR_CALL_TO_ACTION}`)
127+
return throwUserError(`Failed retrieving user account: ${error.message}. ${ERROR_CALL_TO_ACTION}`)
114128
}
115129
}
116130

packages/config/src/main.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { getApiClient } from './api/client.js'
2-
import { getSiteInfo } from './api/site_info.js'
2+
import { getSiteInfo, type MinimalAccount } from './api/site_info.js'
33
import { getInitialBase, getBase, addBase } from './base.js'
44
import { getBuildDir } from './build_dir.js'
55
import { getCachedConfig } from './cached_config.js'
@@ -24,12 +24,31 @@ import { parseConfig } from './parse.js'
2424
import { getConfigPath } from './path.js'
2525
import { getRedirectsPath, addRedirects } from './redirects.js'
2626

27+
export type Config = {
28+
accounts: MinimalAccount[] | undefined
29+
addons: any
30+
api: any
31+
branch: any
32+
buildDir: any
33+
config: any
34+
configPath: any
35+
context: any
36+
env: any
37+
headersPath: any
38+
integrations: any
39+
logs: any
40+
redirectsPath: any
41+
repositoryRoot: any
42+
siteInfo: any
43+
token: any
44+
}
45+
2746
/**
2847
* Load the configuration file.
2948
* Takes an optional configuration file path as input and return the resolved
3049
* `config` together with related properties such as the `configPath`.
3150
*/
32-
export const resolveConfig = async function (opts) {
51+
export const resolveConfig = async function (opts): Promise<Config> {
3352
const {
3453
cachedConfig,
3554
cachedConfigPath,

0 commit comments

Comments
 (0)