Thanks to visit codestin.com
Credit goes to github.com

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
27 changes: 16 additions & 11 deletions src/services/DockerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,22 +330,27 @@ export default class DockerService {
(event) => {
logger.debug(`Status: ${event.status}`);

if (event.progressDetail && event.id) {
// Update the layer progress
layerProgress[event.id] = {
current: event.progressDetail.current || 0,
total: event.progressDetail.total || 0,
};
if (event.id) {
const layer = layerProgress[event.id] || { current: 0, total: 0 };

// Recalculate total progress
const totalCurrent = Object.values(layerProgress).reduce((acc, layer) => acc + layer.current, 0);
const totalSize = Object.values(layerProgress).reduce((acc, layer) => acc + layer.total, 0);
if (event.progressDetail && (event.progressDetail.current || event.progressDetail.total)) {
layer.current = event.progressDetail.current || layer.current;
layer.total = event.progressDetail.total || layer.total;
}
Comment on lines +336 to +339

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The current logic for updating layer.current and layer.total using event.progressDetail.current || layer.current (and similarly for total) can lead to incorrect progress reporting if event.progressDetail.current (or total) is explicitly 0.

For example, if layer.current is 50 and an event arrives with event.progressDetail.current: 0, the expression 0 || 50 evaluates to 50. This means layer.current would not be updated to 0, and the progress would inaccurately remain at 50.

Progress values of 0 are valid and should update the state. Consider updating these properties only if the new value is explicitly provided in event.progressDetail (i.e., not undefined), allowing 0 to be a valid update.

How about refining the update logic to ensure 0 is treated as a valid new value from event.progressDetail?

Suggested change
if (event.progressDetail && (event.progressDetail.current || event.progressDetail.total)) {
layer.current = event.progressDetail.current || layer.current;
layer.total = event.progressDetail.total || layer.total;
}
if (event.progressDetail) {
if (event.progressDetail.current !== undefined) {
layer.current = event.progressDetail.current;
}
if (event.progressDetail.total !== undefined) {
layer.total = event.progressDetail.total;
}
}


if (["Pull complete", "Download complete", "Already exists"].includes(event.status)) {
layer.current = layer.total || layer.current;
}

layerProgress[event.id] = layer;

const totalCurrent = Object.values(layerProgress).reduce((acc, l) => acc + l.current, 0);
const totalSize = Object.values(layerProgress).reduce((acc, l) => acc + l.total, 0);

if (totalSize > 0) {
const percentage = Math.round((totalCurrent / totalSize) * 100);
const percentage = Math.min(100, Math.round((totalCurrent / totalSize) * 100));
logger.debug(`Total progress: ${totalCurrent}/${totalSize} (${percentage}%)`);

// Publish progress updates with a debounce (e.g., every 1 second)
const now = Date.now();
if (now - lastPublishTime >= 1000) {
lastPublishTime = now;
Expand Down