mirror of https://github.com/1Panel-dev/1Panel
perf: 优化应用同步查询接口 (#5241)
parent
400dd79b9f
commit
9af00cc80c
|
@ -5,6 +5,7 @@ import (
|
|||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/docker/docker/api/types"
|
||||
"math"
|
||||
"net/http"
|
||||
"os"
|
||||
|
@ -39,6 +40,7 @@ import (
|
|||
"github.com/1Panel-dev/1Panel/backend/global"
|
||||
"github.com/1Panel-dev/1Panel/backend/utils/common"
|
||||
"github.com/1Panel-dev/1Panel/backend/utils/compose"
|
||||
"github.com/1Panel-dev/1Panel/backend/utils/docker"
|
||||
composeV2 "github.com/1Panel-dev/1Panel/backend/utils/docker"
|
||||
"github.com/1Panel-dev/1Panel/backend/utils/files"
|
||||
"github.com/pkg/errors"
|
||||
|
@ -1118,14 +1120,45 @@ func handleErr(install model.AppInstall, err error, out string) error {
|
|||
}
|
||||
|
||||
func handleInstalled(appInstallList []model.AppInstall, updated bool, sync bool) ([]response.AppInstalledDTO, error) {
|
||||
var res []response.AppInstalledDTO
|
||||
var (
|
||||
res []response.AppInstalledDTO
|
||||
containers []types.Container
|
||||
)
|
||||
if sync {
|
||||
cli, err := docker.NewClient()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer cli.Close()
|
||||
containers, err = cli.ListAllContainers()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
for _, installed := range appInstallList {
|
||||
if updated && (installed.App.Type == "php" || installed.Status == constant.Installing || (installed.App.Key == constant.AppMysql && installed.Version == "5.6.51")) {
|
||||
continue
|
||||
}
|
||||
if sync {
|
||||
if err := syncAppInstallStatus(&installed); err != nil {
|
||||
global.LOG.Error("sync app install status error : ", err)
|
||||
exist := false
|
||||
for _, contain := range containers {
|
||||
if contain.Names[0] == "/"+installed.ContainerName {
|
||||
exist = true
|
||||
switch contain.State {
|
||||
case "exited":
|
||||
installed.Status = constant.Stopped
|
||||
case "running":
|
||||
installed.Status = constant.Running
|
||||
case "paused":
|
||||
installed.Status = constant.Paused
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
if !exist {
|
||||
installed.Status = constant.Error
|
||||
installed.Message = buserr.WithName("ErrContainerNotFound", installed.ContainerName).Error()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ func (c Client) ListContainersByName(names []string) ([]types.Container, error)
|
|||
namesMap = make(map[string]bool)
|
||||
res []types.Container
|
||||
)
|
||||
options.All = false
|
||||
options.All = true
|
||||
if len(names) > 0 {
|
||||
var array []filters.KeyValuePair
|
||||
for _, n := range names {
|
||||
|
@ -77,6 +77,17 @@ func (c Client) ListContainersByName(names []string) ([]types.Container, error)
|
|||
}
|
||||
return res, nil
|
||||
}
|
||||
func (c Client) ListAllContainers() ([]types.Container, error) {
|
||||
var (
|
||||
options container.ListOptions
|
||||
)
|
||||
options.All = true
|
||||
containers, err := c.cli.ContainerList(context.Background(), options)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return containers, nil
|
||||
}
|
||||
|
||||
func (c Client) CreateNetwork(name string) error {
|
||||
_, err := c.cli.NetworkCreate(context.Background(), name, types.NetworkCreate{
|
||||
|
|
|
@ -625,7 +625,7 @@ onMounted(() => {
|
|||
}, 1000);
|
||||
timer = setInterval(() => {
|
||||
search();
|
||||
}, 1000 * 20);
|
||||
}, 1000 * 30);
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
|
|
Loading…
Reference in New Issue