Skip to content

Commit

Permalink
Clean up container removal handling
Browse files Browse the repository at this point in the history
There is no need to re-read the state of all containers from the API --
this is very expensive and adds to the API call avalanche. Just delete
the container from the state.

This also removes the last case where updateContainers() was called
after initialization. Thus eliminate the `init` parameter and rename the
method to initContainers.
  • Loading branch information
martinpitt committed Jul 5, 2023
1 parent 78d768a commit 66516e1
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions src/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ class Application extends React.Component {
.then(scriptResult => scriptResult === "0\n");
}

updateContainers(system, init) {
initContainers(system) {
return client.getContainers(system)
.then(reply => Promise.all(
(reply || []).map(container =>
Expand All @@ -203,7 +203,7 @@ class Application extends React.Component {
)
))
.then(reply => {
debug(system, "updateContainers init", init, "getContainers", JSON.stringify(reply));
debug(system, "initContainers getContainers", JSON.stringify(reply));
this.setState(prevState => {
// Copy only containers that could not be deleted with this event
// So when event from system come, only copy user containers and vice versa
Expand All @@ -222,11 +222,9 @@ class Application extends React.Component {
[system ? "systemContainersLoaded" : "userContainersLoaded"]: true,
};
});
if (init) {
this.updateContainerStats(system);
for (const container of reply || []) {
this.inspectContainerDetail(container.Id, system);
}
this.updateContainerStats(system);
for (const container of reply || []) {
this.inspectContainerDetail(container.Id, system);
}
})
.catch(console.log);
Expand Down Expand Up @@ -412,13 +410,10 @@ class Application extends React.Component {
this.updateContainer(event.Actor.ID, system, event);
break;
case 'remove':
this.updateContainers(system).then(() => {
// HACK: we don't get a pod event when a container in a pod is removed.
// https://github.com/containers/podman/issues/15408
if (event.Actor.Attributes.podId)
this.updatePod(event.Actor.Attributes.podId, system);
else
this.updatePods(system);
this.setState(prevState => {
const containers = { ...prevState.containers };
delete containers[event.id + system.toString()];
return { containers };
});
break;
/* The following events need only to update the Image list */
Expand Down Expand Up @@ -488,7 +483,7 @@ class Application extends React.Component {
cgroupVersion: reply.host.cgroupVersion,
});
this.updateImages(system);
this.updateContainers(system, true);
this.initContainers(system);
this.updatePods(system);
client.streamEvents(system,
message => this.handleEvent(message, system))
Expand Down

0 comments on commit 66516e1

Please sign in to comment.