Merge pull request #49 from IceWhaleTech/dev

fixed bug
This commit is contained in:
link 2021-12-10 14:18:01 +08:00 committed by GitHub
commit 4c1cbc98a4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 9 deletions

View file

@ -70,5 +70,5 @@ type SystemConfig struct {
}
type CasaOSGlobalVariables struct {
AddApp bool
AppChange bool
}

View file

@ -466,7 +466,7 @@ func InstallApp(c *gin.Context) {
// m.PortMap = m.Port
//}
service.MyService.App().SaveContainer(md)
config.CasaOSGlobalVariables.AddApp = true
config.CasaOSGlobalVariables.AppChange = true
}()
@ -743,7 +743,7 @@ func UnInstallApp(c *gin.Context) {
// }
//}
}
config.CasaOSGlobalVariables.AppChange = true
c.JSON(http.StatusOK, model.Result{Success: oasis_err2.SUCCESS, Message: oasis_err2.GetMsg(oasis_err2.SUCCESS)})
}

View file

@ -5,6 +5,7 @@ import (
"encoding/json"
"io"
"io/ioutil"
"reflect"
"runtime"
"strings"
"sync"
@ -269,7 +270,6 @@ func (a *appStruct) GetHardwareUsage() []model.DockerStatsModel {
a.GetHardwareUsageSteam()
}()
}
// 切一下,再次分配任务
runtime.Gosched()
}
list := []model.DockerStatsModel{}
@ -299,11 +299,22 @@ func (a *appStruct) GetHardwareUsageSteam() {
ctx, cancel := context.WithCancel(ctx)
var lm []model2.AppListDBModel
a.db.Table(model2.CONTAINERTABLENAME).Select("label,icon,container_id").Where("origin != ?", "system").Find(&lm)
a.db.Table(model2.CONTAINERTABLENAME).Select("label,title,icon,container_id").Where("origin != ?", "system").Find(&lm)
var list []types.ContainerStats
for i := 0; i < 100; i++ {
if config.CasaOSGlobalVariables.AddApp {
a.db.Table(model2.CONTAINERTABLENAME).Select("label,icon,container_id").Where("origin != ?", "system").Find(&lm)
if config.CasaOSGlobalVariables.AppChange {
lm = []model2.AppListDBModel{}
config.CasaOSGlobalVariables.AppChange = false
a.db.Table(model2.CONTAINERTABLENAME).Select("label,title,icon,container_id").Where("origin != ?", "system").Find(&lm)
dataApps := dataStr
lock.Lock()
dataStr = make(map[string]model.DockerStatsModel)
for _, v := range lm {
if !reflect.DeepEqual(dataApps[v.ContainerId], model.DockerStatsModel{}) {
dataStr[v.ContainerId] = dataApps[v.ContainerId]
}
}
lock.Unlock()
}
var wg sync.WaitGroup
for _, v := range lm {
@ -322,10 +333,13 @@ func (a *appStruct) GetHardwareUsageSteam() {
lock.Lock()
dockerStats := model.DockerStatsModel{}
dockerStats.Pre = dataStr[v.ContainerId].Data
dockerStats.Data = data
dockerStats.Icon = v.Icon
dockerStats.Title = v.Label
if len(v.Label) > 0 {
dockerStats.Title = v.Label
} else {
dockerStats.Title = v.Title
}
dataStr[v.ContainerId] = dockerStats
lock.Unlock()
}(v, lock)