perf: 优化应用同步查询接口 (#5241)

pull/5242/head
zhengkunwang 2024-05-31 17:57:20 +08:00 committed by GitHub
parent 400dd79b9f
commit 9af00cc80c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 49 additions and 5 deletions

View File

@ -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()
}
}

View File

@ -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{

View File

@ -625,7 +625,7 @@ onMounted(() => {
}, 1000);
timer = setInterval(() => {
search();
}, 1000 * 20);
}, 1000 * 30);
});
onUnmounted(() => {