Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 27 additions & 13 deletions packages/config/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,33 @@ export const resolveConfig = async function (opts) {
featureFlags,
} = await normalizeOpts(optsA)

const { siteInfo, accounts, addons, integrations } = await getSiteInfo({
api,
context,
siteId,
accountId,
mode,
siteFeatureFlagPrefix,
offline,
featureFlags,
testOpts,
token,
extensionApiBaseUrl,
})
let { siteInfo, accounts, addons, integrations } = parsedCachedConfig || {}

// If we have cached site info, we don't need to fetch it again
const useCachedSiteInfo = Boolean(
featureFlags?.use_cached_site_info && siteInfo && accounts && addons && integrations,
)

if (!useCachedSiteInfo) {
const updatedSiteInfo = await getSiteInfo({
api,
context,
siteId,
accountId,
mode,
siteFeatureFlagPrefix,
offline,
featureFlags,
testOpts,
token,
extensionApiBaseUrl,
})

siteInfo = updatedSiteInfo.siteInfo
accounts = updatedSiteInfo.accounts
addons = updatedSiteInfo.addons
integrations = updatedSiteInfo.integrations
}

const { defaultConfig: defaultConfigA, baseRelDir: baseRelDirA } = parseDefaultConfig({
defaultConfig,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[build]
command = "echo command"
47 changes: 47 additions & 0 deletions packages/config/tests/api/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -470,3 +470,50 @@ test('baseRelDir is true if build.base is overridden', async (t) => {
.runConfigServer([SITE_INFO_BASE_REL_DIR, FETCH_INTEGRATIONS_EMPTY_RESPONSE])
t.snapshot(normalizeOutput(output))
})

test('It does not fetch site info if cachedConfig is provided, use_cached_site_info is true and there is siteInfo, accounts, addons and integrations on cachedConfig', async (t) => {
const cachedConfig = await new Fixture('./fixtures/cached_config').runWithConfigAsObject()
const { requests } = await new Fixture('./fixtures/cached_config')
.withFlags({
cachedConfig,
siteId: 'test',
mode: 'dev',
token: 'test',
accountId: 'account1',
featureFlags: {
use_cached_site_info: true,
},
})
.runConfigServer([SITE_INFO_DATA, SITE_INTEGRATIONS_RESPONSE, TEAM_INSTALLATIONS_META_RESPONSE])

t.assert(requests.length === 0)
})

test('It fetches site info if cachedConfig is provided, use_cached_site_info is true and there is no siteInfo, accounts, addons or integrations on cachedConfig', async (t) => {
const cachedConfig = await new Fixture('./fixtures/cached_config').runWithConfigAsObject()
const { requests } = await new Fixture('./fixtures/cached_config')
.withFlags({
cachedConfig,
siteId: 'test',
mode: 'dev',
token: 'test',
accountId: 'account1',
featureFlags: {
use_cached_site_info: true,
},
})
.runConfigServer([SITE_INFO_DATA, SITE_INTEGRATIONS_RESPONSE, TEAM_INSTALLATIONS_META_RESPONSE])

t.assert(requests.length === 0)
})

test('It fetches site info if cachedConfig is provided, use_cached_site_info is false', async (t) => {
const cachedConfig = await new Fixture('./fixtures/cached_config').runWithConfigAsObject()
const { requests } = await new Fixture('./fixtures/cached_config')
.withFlags({
cachedConfig,
})
.runConfigServer([SITE_INFO_DATA, SITE_INTEGRATIONS_RESPONSE, TEAM_INSTALLATIONS_META_RESPONSE])

t.assert(requests.length === 0)
})
Loading