From 9851e66a0e11c9fe34aeb005cbc84d34dc53f4e0 Mon Sep 17 00:00:00 2001 From: tzwang Date: Fri, 30 Aug 2024 17:25:01 +0800 Subject: [PATCH] updated getdeploytaskbytype logic Former-commit-id: 518ccaa4b1ae7a85cd3f16f110aa9aa4f06c0799 --- .../inference/getdeploytasksbytypelogic.go | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) 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:]...) } } }