mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-10-08 22:46:51 +08:00
fix: Optimize application recommendation logic (#10128)
This commit is contained in:
parent
aad79077bf
commit
ebdc3f05de
2 changed files with 33 additions and 19 deletions
|
@ -33,6 +33,8 @@ type IAppRepo interface {
|
||||||
BatchDelete(ctx context.Context, apps []model.App) error
|
BatchDelete(ctx context.Context, apps []model.App) error
|
||||||
DeleteByIDs(ctx context.Context, ids []uint) error
|
DeleteByIDs(ctx context.Context, ids []uint) error
|
||||||
DeleteBy(opts ...DBOption) error
|
DeleteBy(opts ...DBOption) error
|
||||||
|
|
||||||
|
GetTopRecomment() ([]string, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewIAppRepo() IAppRepo {
|
func NewIAppRepo() IAppRepo {
|
||||||
|
@ -123,6 +125,21 @@ func (a AppRepo) GetBy(opts ...DBOption) ([]model.App, error) {
|
||||||
return apps, nil
|
return apps, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a AppRepo) GetTopRecomment() ([]string, error) {
|
||||||
|
var (
|
||||||
|
apps []model.App
|
||||||
|
names []string
|
||||||
|
)
|
||||||
|
db := getDb().Model(&model.App{})
|
||||||
|
if err := db.Order("recommend asc").Limit(6).Find(&apps).Error; err != nil {
|
||||||
|
return names, err
|
||||||
|
}
|
||||||
|
for _, item := range apps {
|
||||||
|
names = append(names, item.Key)
|
||||||
|
}
|
||||||
|
return names, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (a AppRepo) BatchCreate(ctx context.Context, apps []model.App) error {
|
func (a AppRepo) BatchCreate(ctx context.Context, apps []model.App) error {
|
||||||
return getTx(ctx).Omit(clause.Associations).Create(&apps).Error
|
return getTx(ctx).Omit(clause.Associations).Create(&apps).Error
|
||||||
}
|
}
|
||||||
|
|
|
@ -268,10 +268,7 @@ func (u *DashboardService) LoadCurrentInfo(ioOption string, netOption string) *d
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *DashboardService) LoadAppLauncher(ctx *gin.Context) ([]dto.AppLauncher, error) {
|
func (u *DashboardService) LoadAppLauncher(ctx *gin.Context) ([]dto.AppLauncher, error) {
|
||||||
var (
|
var data []dto.AppLauncher
|
||||||
data []dto.AppLauncher
|
|
||||||
recommendList []dto.AppLauncher
|
|
||||||
)
|
|
||||||
appInstalls, err := appInstallRepo.ListBy(context.Background())
|
appInstalls, err := appInstallRepo.ListBy(context.Background())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return data, err
|
return data, err
|
||||||
|
@ -281,8 +278,11 @@ func (u *DashboardService) LoadAppLauncher(ctx *gin.Context) ([]dto.AppLauncher,
|
||||||
return data, err
|
return data, err
|
||||||
}
|
}
|
||||||
|
|
||||||
showList, _ := launcherRepo.ListName()
|
showList, err := launcherRepo.ListName()
|
||||||
defaultList := []string{"openresty", "mysql", "halo", "redis", "maxkb", "wordpress"}
|
defaultList, err := appRepo.GetTopRecomment()
|
||||||
|
if err != nil {
|
||||||
|
return data, nil
|
||||||
|
}
|
||||||
allList := common.RemoveRepeatStr(append(defaultList, showList...))
|
allList := common.RemoveRepeatStr(append(defaultList, showList...))
|
||||||
for _, showItem := range allList {
|
for _, showItem := range allList {
|
||||||
var itemData dto.AppLauncher
|
var itemData dto.AppLauncher
|
||||||
|
@ -317,24 +317,21 @@ func (u *DashboardService) LoadAppLauncher(ctx *gin.Context) ([]dto.AppLauncher,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ArryContains(defaultList, showItem) && len(itemData.Detail) == 0 {
|
if (ArryContains(showList, showItem) && len(itemData.Detail) != 0) ||
|
||||||
itemData.IsRecommend = true
|
(ArryContains(defaultList, showItem) && len(itemData.Detail) == 0) {
|
||||||
recommendList = append(recommendList, itemData)
|
data = append(data, itemData)
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
if !ArryContains(showList, showItem) && len(itemData.Detail) != 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
data = append(data, itemData)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sort.Slice(recommendList, func(i, j int) bool {
|
|
||||||
return recommendList[i].Recommend < recommendList[j].Recommend
|
|
||||||
})
|
|
||||||
sort.Slice(data, func(i, j int) bool {
|
sort.Slice(data, func(i, j int) bool {
|
||||||
return data[i].Name < data[j].Name
|
if data[i].IsInstall != data[j].IsInstall {
|
||||||
|
return data[i].IsInstall
|
||||||
|
}
|
||||||
|
if data[i].IsInstall && data[j].IsInstall {
|
||||||
|
return data[i].Name < data[j].Name
|
||||||
|
}
|
||||||
|
return data[i].Recommend < data[j].Recommend
|
||||||
})
|
})
|
||||||
data = append(data, recommendList...)
|
|
||||||
return data, nil
|
return data, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue