From 7c5434cf1105dd53d53b04ee60a52102f1fa87c5 Mon Sep 17 00:00:00 2001 From: chenyifan01 Date: Wed, 14 Dec 2022 16:57:33 +0800 Subject: [PATCH] #3364 repo-square:fix bug --- models/repo.go | 9 +-------- routers/repo/ai_model_manage.go | 8 ++++---- services/repository/repository.go | 4 ++++ 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/models/repo.go b/models/repo.go index dbd792502..e390ef70d 100755 --- a/models/repo.go +++ b/models/repo.go @@ -2944,14 +2944,7 @@ func ResetRepoDatasetNum(repoId int64) error { } func ResetRepoModelNum(repoId int64) error { - n, err := x.Where("repo_id = ? and size > 0 ", repoId).Count(&AiModelManage{}) - if err != nil { - return err - } - r := Repository{ - ModelCnt: n, - } - _, err = x.Cols("model_cnt").Where("id = ?", repoId).Update(&r) + _, err := x.Exec("update repository set model_cnt = (select count(1) from ai_model_manage where ai_model_manage.repo_id = ? and size > 0) where id = ?", repoId, repoId) return err } diff --git a/routers/repo/ai_model_manage.go b/routers/repo/ai_model_manage.go index a45f21cca..fadcff051 100644 --- a/routers/repo/ai_model_manage.go +++ b/routers/repo/ai_model_manage.go @@ -178,7 +178,7 @@ func updateStatus(id string, modelSize int64, status int, modelPath string, stat } if m != nil { if modelSize > 0 && m.Size == 0 { - go repository.IncreaseRepoModelNum(m.RepoId) + go repository.ResetRepoModelNum(m.RepoId) } } @@ -337,7 +337,7 @@ func UpdateModelSize(modeluuid string) { } } if model.Size == 0 && size > 0 { - go repository.IncreaseRepoModelNum(model.RepoId) + go repository.ResetRepoModelNum(model.RepoId) } } else { log.Info("not found model,uuid=" + modeluuid) @@ -498,7 +498,7 @@ func DeleteModelFile(ctx *context.Context) { } } if (model.Size - totalSize) <= 0 { - go repository.DecreaseRepoModelNum(model.RepoId) + go repository.ResetRepoModelNum(model.RepoId) } } ctx.JSON(200, map[string]string{ @@ -569,7 +569,7 @@ func deleteModelByID(ctx *context.Context, id string) error { } } if model.Size > 0 { - go repository.DecreaseRepoModelNum(model.RepoId) + go repository.ResetRepoModelNum(model.RepoId) } } } diff --git a/services/repository/repository.go b/services/repository/repository.go index 41fc1dcc4..a5c7c2fc4 100644 --- a/services/repository/repository.go +++ b/services/repository/repository.go @@ -342,6 +342,10 @@ func IncreaseRepoModelNum(repoId int64, engines ...*xorm.Engine) error { return models.OperateRepoModelNum(repoId, 1, engines...) } +func ResetRepoModelNum(repoId int64) error { + return models.ResetRepoModelNum(repoId) +} + func DecreaseRepoDatasetNum(datasetID int64, engines ...*xorm.Engine) error { dataset, err := models.GetDatasetByID(datasetID) if err != nil {