mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-10-16 18:36:21 +08:00
perf: 优化应用同步查询接口 (#5241)
This commit is contained in:
parent
400dd79b9f
commit
9af00cc80c
3 changed files with 49 additions and 5 deletions
|
@ -5,6 +5,7 @@ import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/docker/docker/api/types"
|
||||||
"math"
|
"math"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
@ -39,6 +40,7 @@ import (
|
||||||
"github.com/1Panel-dev/1Panel/backend/global"
|
"github.com/1Panel-dev/1Panel/backend/global"
|
||||||
"github.com/1Panel-dev/1Panel/backend/utils/common"
|
"github.com/1Panel-dev/1Panel/backend/utils/common"
|
||||||
"github.com/1Panel-dev/1Panel/backend/utils/compose"
|
"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"
|
composeV2 "github.com/1Panel-dev/1Panel/backend/utils/docker"
|
||||||
"github.com/1Panel-dev/1Panel/backend/utils/files"
|
"github.com/1Panel-dev/1Panel/backend/utils/files"
|
||||||
"github.com/pkg/errors"
|
"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) {
|
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 {
|
for _, installed := range appInstallList {
|
||||||
if updated && (installed.App.Type == "php" || installed.Status == constant.Installing || (installed.App.Key == constant.AppMysql && installed.Version == "5.6.51")) {
|
if updated && (installed.App.Type == "php" || installed.Status == constant.Installing || (installed.App.Key == constant.AppMysql && installed.Version == "5.6.51")) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if sync {
|
if sync {
|
||||||
if err := syncAppInstallStatus(&installed); err != nil {
|
exist := false
|
||||||
global.LOG.Error("sync app install status error : ", err)
|
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)
|
namesMap = make(map[string]bool)
|
||||||
res []types.Container
|
res []types.Container
|
||||||
)
|
)
|
||||||
options.All = false
|
options.All = true
|
||||||
if len(names) > 0 {
|
if len(names) > 0 {
|
||||||
var array []filters.KeyValuePair
|
var array []filters.KeyValuePair
|
||||||
for _, n := range names {
|
for _, n := range names {
|
||||||
|
@ -77,6 +77,17 @@ func (c Client) ListContainersByName(names []string) ([]types.Container, error)
|
||||||
}
|
}
|
||||||
return res, nil
|
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 {
|
func (c Client) CreateNetwork(name string) error {
|
||||||
_, err := c.cli.NetworkCreate(context.Background(), name, types.NetworkCreate{
|
_, err := c.cli.NetworkCreate(context.Background(), name, types.NetworkCreate{
|
||||||
|
|
|
@ -625,7 +625,7 @@ onMounted(() => {
|
||||||
}, 1000);
|
}, 1000);
|
||||||
timer = setInterval(() => {
|
timer = setInterval(() => {
|
||||||
search();
|
search();
|
||||||
}, 1000 * 20);
|
}, 1000 * 30);
|
||||||
});
|
});
|
||||||
|
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
|
|
Loading…
Add table
Reference in a new issue