Skip to content

Commit

Permalink
Avoid API queries for some events
Browse files Browse the repository at this point in the history
These events change the state in a predictable way. Avoid the expensive
updateContainer() call for these, to avoid multiple calls overlapping
each other. See containers/podman#19124
  • Loading branch information
martinpitt committed Jul 5, 2023
1 parent fdd9a1a commit 8438f4c
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions src/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,15 @@ class Application extends React.Component {
.catch(console.log);
}

updateContainerProperty(id, system, name, value) {
this.setState(prevState => {
const containers = { ...prevState.containers };
const newContainer = { ...containers[id + system.toString()], [name]: value };
containers[id + system.toString()] = newContainer;
return { containers };
});
}

updateImage(id, system) {
client.getImages(system, id)
.then(reply => {
Expand Down Expand Up @@ -380,6 +389,22 @@ class Application extends React.Component {
case 'init':
case 'wait':
break;

/* The following events just change the State property */
case 'pause':
this.updateContainerProperty(id, system, "State", "paused");
break;
case 'unpause':
this.updateContainerProperty(id, system, "State", "running");
break;
case 'stop':
this.updateContainerProperty(id, system, "State", "stopped");
break;
case 'died':
case 'exec_died':
this.updateContainerProperty(id, system, "State", "exited");
break;

/* The following events need only to update the Container list
* We do get the container affected in the event object but for
* now we 'll do a batch update
Expand All @@ -394,19 +419,14 @@ class Application extends React.Component {
break;
case 'checkpoint':
case 'create':
case 'died':
case 'exec_died':
case 'kill':
case 'cleanup':
case 'mount':
case 'pause':
case 'prune':
case 'restart':
case 'restore':
case 'stop':
case 'sync':
case 'unmount':
case 'unpause':
case 'rename': // rename event is available starting podman v4.1; until then the container does not get refreshed after renaming
this.updateContainer(id, system, event);
break;
Expand Down

0 comments on commit 8438f4c

Please sign in to comment.