Skip to content

Commit 81f0a74

Browse files
committed
fix: add defined services count to improve client status accuracy
1 parent bafed14 commit 81f0a74

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

source/compose.manager/php/compose_manager_main.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2029,6 +2029,7 @@ function refreshStackRow(stackId, project) {
20292029
}
20302030
// Update cache with fresh data
20312031
stackContainersCache[stackId] = containers;
2032+
stackDefinedServicesCache[stackId] = response.definedServices || containers.length;
20322033
// Now update the row using the fresh cache
20332034
updateParentStackFromContainers(stackId, project);
20342035
// If details are expanded, refresh them too
@@ -2530,6 +2531,7 @@ function ComposeLogs(pathOrProject, profile = "") {
25302531
var currentStackId = null;
25312532
var expandedStacks = {};
25322533
var stackContainersCache = {};
2534+
var stackDefinedServicesCache = {}; // Cache for defined service counts
25332535
// Track stacks currently loading details to prevent concurrent reloads
25342536
var stackDetailsLoading = {};
25352537
// Suppress immediate refresh after a render to avoid loops
@@ -3636,6 +3638,7 @@ function loadStackContainerDetails(stackId, project) {
36363638
}
36373639

36383640
stackContainersCache[stackId] = containers;
3641+
stackDefinedServicesCache[stackId] = response.definedServices || containers.length;
36393642
composeClientDebug('[loadStackContainerDetails] success', {
36403643
stackId: stackId,
36413644
project: project,
@@ -3925,11 +3928,13 @@ function renderContainerDetails(stackId, containers, project) {
39253928
// Build a condensed stackInfo object from the stackContainersCache for a stack
39263929
function buildStackInfoFromCache(stackId, project) {
39273930
var containers = stackContainersCache[stackId] || [];
3931+
var definedServices = stackDefinedServicesCache[stackId] || containers.length;
39283932
var stackInfo = {
39293933
projectName: project,
39303934
containers: [],
39313935
isRunning: false,
3932-
hasUpdate: false
3936+
hasUpdate: false,
3937+
totalServices: definedServices // Track total defined services for accurate status
39333938
};
39343939
containers.forEach(function(c) {
39353940
var name = c.Name || c.Service || '';
@@ -4006,7 +4011,8 @@ function updateParentStackFromContainers(stackId, project) {
40064011
var runningCount = stackInfo.containers.filter(function(c) {
40074012
return c.isRunning;
40084013
}).length;
4009-
var totalCount = stackInfo.containers.length;
4014+
// Use totalServices (defined services) if available, otherwise fall back to actual container count
4015+
var totalCount = stackInfo.totalServices || stackInfo.containers.length;
40104016
var anyRunning = runningCount > 0;
40114017
var anyPaused = stackInfo.containers.some(function(c) {
40124018
return !c.isRunning && (c.updateStatus === 'paused' || c.updateStatus === 'paused');

source/compose.manager/php/exec.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,16 @@ function getPostScript(): string
561561
$updateStatus = json_decode(file_get_contents($updateStatusFile), true) ?: [];
562562
}
563563

564+
// Get defined service count (like compose_list.php does)
565+
// This ensures the client shows the correct total even if not all services are running
566+
$definedServices = 0;
567+
$configCmd = "docker compose {$args['files']} {$args['envFile']} config --services 2>/dev/null";
568+
$configOutput = shell_exec($configCmd);
569+
if ($configOutput) {
570+
$services = array_filter(explode("\n", trim($configOutput)));
571+
$definedServices = count($services);
572+
}
573+
564574
if ($output) {
565575
// docker compose ps --format json outputs one JSON object per line
566576
$lines = explode("\n", trim($output));
@@ -724,7 +734,7 @@ function getPostScript(): string
724734
}
725735
}
726736

727-
echo json_encode(['result' => 'success', 'containers' => $containers, 'projectName' => $projectName]);
737+
echo json_encode(['result' => 'success', 'containers' => $containers, 'definedServices' => $definedServices, 'projectName' => $projectName]);
728738
break;
729739
case 'containerAction':
730740
$containerName = isset($_POST['container']) ? trim($_POST['container']) : "";

0 commit comments

Comments
 (0)