diff --git a/internal/logic/inference/getdeploytasksbytypelogic.go b/internal/logic/inference/getdeploytasksbytypelogic.go index c3fbdbfc..f1cd5268 100644 --- a/internal/logic/inference/getdeploytasksbytypelogic.go +++ b/internal/logic/inference/getdeploytasksbytypelogic.go @@ -47,7 +47,7 @@ func (l *GetDeployTasksByTypeLogic) GetDeployTasksByType(req *types.GetDeployTas return nil, err } if len(inslist) == 0 { - removeItem(listcopy, task.Id) + removeItem(&listcopy, task.Id) } var count int for _, ins := range inslist { @@ -59,17 +59,26 @@ func (l *GetDeployTasksByTypeLogic) GetDeployTasksByType(req *types.GetDeployTas continue } - removeItem(listcopy, task.Id) + removeItem(&listcopy, task.Id) } resp.List = listcopy return resp, nil } -func removeItem(items []*models.AiDeployInstanceTask, id int64) { - for i := len(items) - 1; i >= 0; i-- { - if items[i].Id == id { - items = append(items[:i], items[i+1:]...) +func removeItem(items *[]*models.AiDeployInstanceTask, id int64) { + if len(*items) == 0 { + return + } + if len(*items) == 1 { + if (*items)[0].Id == id { + (*items) = nil + return + } + } + for i := len(*items) - 1; i >= 0; i-- { + if (*items)[i].Id == id { + *items = append((*items)[:i], (*items)[i+1:]...) } } }