refactor(stacks): plumb sourceType through requireComposeFile to avoid redundant lookup

startStack, restartStack, stopStack, and downStack each ran a separate
getStackSource query just to determine isGitStack for useOverrideFile,
even though requireComposeFile -> getStackComposeFile already looks up
the same stack_sources record.

Return sourceType from getStackComposeFile (GetComposeFileResult) and
requireComposeFile (RequireComposeResult), and have all four callers
read result.sourceType instead of querying the database again. No
behavior change: useOverrideFile is still set to true exactly when the
stack's source type is 'git'.
This commit is contained in:
Björn Strausmann authored and Jarek Krochmalski committed 2026-07-31 04:58:47 +02:00
1 parent 144a73a10a
commit 36dac8b030
1 file changed
+22 -14
+22 -14
View File
@@ -479,6 +479,8 @@ export interface GetComposeFileResult {
composePath?: string | null; composePath?: string | null;
envPath?: string | null; envPath?: string | null;
suggestedEnvPath?: string; suggestedEnvPath?: string;
/** Stack source type (internal/git/external), from the stack_sources lookup already done here */
sourceType?: StackSourceType;
} }
/** /**
@@ -538,7 +540,8 @@ export async function getStackComposeFile(
stackDir, stackDir,
composePath: source.composePath, composePath: source.composePath,
envPath: source.envPath, envPath: source.envPath,
suggestedEnvPath suggestedEnvPath,
sourceType: source.sourceType
}; };
} catch (error) { } catch (error) {
const message = error instanceof Error ? error.message : 'Unknown error'; const message = error instanceof Error ? error.message : 'Unknown error';
@@ -572,7 +575,8 @@ export async function getStackComposeFile(
stackDir, stackDir,
// Always return the actual resolved paths for display // Always return the actual resolved paths for display
composePath: actualComposePath, composePath: actualComposePath,
envPath: envExists ? envFilePath : null envPath: envExists ? envFilePath : null,
sourceType: source.sourceType
}; };
} }
} }
@@ -2013,6 +2017,8 @@ export interface RequireComposeResult {
composePath?: string; composePath?: string;
/** Full path to the env file (for --env-file flag) */ /** Full path to the env file (for --env-file flag) */
envPath?: string; envPath?: string;
/** Stack source type (internal/git/external), plumbed through from getStackComposeFile to avoid a redundant getStackSource lookup in callers */
sourceType?: StackSourceType;
} }
/** /**
@@ -2087,7 +2093,8 @@ export async function requireComposeFile(
nonSecretVars, nonSecretVars,
stackDir: composeResult.stackDir, stackDir: composeResult.stackDir,
composePath: composeResult.composePath ?? undefined, composePath: composeResult.composePath ?? undefined,
envPath: envFilePath ?? undefined envPath: envFilePath ?? undefined,
sourceType: composeResult.sourceType
}; };
} }
@@ -2172,9 +2179,10 @@ export async function startStack(
return fallback; return fallback;
} }
// Check if this is a git stack - git stacks need useOverrideFile to write .env.dockhand // Git stacks need useOverrideFile to write .env.dockhand with DB overrides.
const source = await getStackSource(stackName, envId); // sourceType is plumbed through from requireComposeFile (which already looked
const isGitStack = source?.sourceType === 'git'; // it up via getStackComposeFile/getStackSource) to avoid a redundant DB lookup.
const isGitStack = result.sourceType === 'git';
const opts: ComposeCommandOptions = { stackName, envId, workingDir: result.stackDir, composePath: result.composePath, envPath: result.envPath, useOverrideFile: isGitStack }; const opts: ComposeCommandOptions = { stackName, envId, workingDir: result.stackDir, composePath: result.composePath, envPath: result.envPath, useOverrideFile: isGitStack };
@@ -2212,9 +2220,9 @@ export async function stopStack(
return fallback; return fallback;
} }
// Check if this is a git stack - git stacks need useOverrideFile to write .env.dockhand // Git stacks need useOverrideFile to write .env.dockhand with DB overrides.
const source = await getStackSource(stackName, envId); // sourceType is plumbed through from requireComposeFile to avoid a redundant DB lookup.
const isGitStack = source?.sourceType === 'git'; const isGitStack = result.sourceType === 'git';
const composeResult = await executeComposeCommand( const composeResult = await executeComposeCommand(
'stop', 'stop',
@@ -2256,8 +2264,8 @@ export async function restartStack(
// Git stacks need useOverrideFile to write .env.dockhand with DB overrides. // Git stacks need useOverrideFile to write .env.dockhand with DB overrides.
// Non-git stacks still pass nonSecretVars for legacy support (stacks without // Non-git stacks still pass nonSecretVars for legacy support (stacks without
// .env files on disk get vars injected via shell env at executeLocalCompose). // .env files on disk get vars injected via shell env at executeLocalCompose).
const source = await getStackSource(stackName, envId); // sourceType is plumbed through from requireComposeFile to avoid a redundant DB lookup.
const isGitStack = source?.sourceType === 'git'; const isGitStack = result.sourceType === 'git';
const opts: ComposeCommandOptions = { stackName, envId, workingDir: result.stackDir, composePath: result.composePath, envPath: result.envPath, useOverrideFile: isGitStack }; const opts: ComposeCommandOptions = { stackName, envId, workingDir: result.stackDir, composePath: result.composePath, envPath: result.envPath, useOverrideFile: isGitStack };
@@ -2293,9 +2301,9 @@ export async function downStack(
return withContainerFallback(stackName, envId, 'stop'); return withContainerFallback(stackName, envId, 'stop');
} }
// Check if this is a git stack - git stacks need useOverrideFile to write .env.dockhand // Git stacks need useOverrideFile to write .env.dockhand with DB overrides.
const source = await getStackSource(stackName, envId); // sourceType is plumbed through from requireComposeFile to avoid a redundant DB lookup.
const isGitStack = source?.sourceType === 'git'; const isGitStack = result.sourceType === 'git';
const composeResult = await executeComposeCommand( const composeResult = await executeComposeCommand(
'down', 'down',