Browse Source

#3364

repo-square:fix bug
repo-square
chenyifan01 2 years ago
parent
commit
7c5434cf11
3 changed files with 9 additions and 12 deletions
  1. +1
    -8
      models/repo.go
  2. +4
    -4
      routers/repo/ai_model_manage.go
  3. +4
    -0
      services/repository/repository.go

+ 1
- 8
models/repo.go View File

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



+ 4
- 4
routers/repo/ai_model_manage.go View File

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


+ 4
- 0
services/repository/repository.go View File

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


Loading…
Cancel
Save