Skip to content
Merged
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
11 changes: 8 additions & 3 deletions web/strategy-switch-console/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -694,8 +694,9 @@ async function loadCurrentStrategies(accountOptions, env) {
const repositories = platformRepositories(env);

const variableCache = new Map();
const readVariable = (repository, scope, githubEnvironment, name) => {
const readVariable = (repository, scope, githubEnvironment, name, { skipCache = false } = {}) => {
const cacheKey = [repository, scope, githubEnvironment || "", name].join("|");
if (skipCache) variableCache.delete(cacheKey);
if (!variableCache.has(cacheKey)) {
variableCache.set(cacheKey, fetchGithubVariable(token, repository, scope, githubEnvironment, name));
}
Expand Down Expand Up @@ -867,6 +868,12 @@ async function resolveCurrentStrategyForAccount({ platform, option, optionsCount
});
// Await in parallel: each reads a different variable so
// there is no risk of hammering the same GitHub API endpoint.
// Read RUNTIME_TARGET_JSON first with retry — parallel reads inside
// Promise.all can hit GitHub secondary rate limits and return empty.
let runtimeTargetValue = await readVariable(repository, variableScope, githubEnvironment, "RUNTIME_TARGET_JSON");
if (!runtimeTargetValue) {
runtimeTargetValue = await readVariable(repository, variableScope, githubEnvironment, "RUNTIME_TARGET_JSON", { skipCache: true });
}
const [
reservedCashPayload,
incomeLayerPayload,
Expand All @@ -875,7 +882,6 @@ async function resolveCurrentStrategyForAccount({ platform, option, optionsCount
dcaPayload,
ibitZscorePayload,
cashOnlyPayload,
runtimeTargetValue,
] = await Promise.all([
reservedCashPayloadPromise,
incomeLayerPayloadPromise,
Expand All @@ -884,7 +890,6 @@ async function resolveCurrentStrategyForAccount({ platform, option, optionsCount
dcaPayloadPromise,
ibitZscorePayloadPromise,
cashOnlyPayloadPromise,
readVariable(repository, variableScope, githubEnvironment, "RUNTIME_TARGET_JSON"),
]);
const runtimeTarget = parseJsonObject(runtimeTargetValue);
const runtimeTargetMatches = runtimeTarget && runtimeTargetMatchesAccount(runtimeTarget, platform, option);
Expand Down
Loading