From c57d265c69a83ae451bcd73a192957aa52eab24d Mon Sep 17 00:00:00 2001 From: zouap Date: Fri, 10 Dec 2021 09:01:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- models/ai_model_manage.go | 2 +- routers/repo/ai_model_manage.go | 60 +++++++++++++++++++-------------- 2 files changed, 35 insertions(+), 27 deletions(-) diff --git a/models/ai_model_manage.go b/models/ai_model_manage.go index ace51002d..712e72d98 100644 --- a/models/ai_model_manage.go +++ b/models/ai_model_manage.go @@ -31,7 +31,7 @@ type AiModelManage struct { CodeCommitID string `xorm:"NULL"` UserId int64 `xorm:"NOT NULL"` UserName string - UserRelAvatarLink string `xorm:"NULL"` + UserRelAvatarLink string TrainTaskInfo string `xorm:"text NULL"` CreatedUnix timeutil.TimeStamp `xorm:"created"` UpdatedUnix timeutil.TimeStamp `xorm:"updated"` diff --git a/routers/repo/ai_model_manage.go b/routers/repo/ai_model_manage.go index 5103c2a5e..612458058 100644 --- a/routers/repo/ai_model_manage.go +++ b/routers/repo/ai_model_manage.go @@ -71,25 +71,24 @@ func saveModelByParameters(jobId string, versionName string, name string, versio aiTaskJson, _ := json.Marshal(aiTask) model := &models.AiModelManage{ - ID: id, - Version: version, - VersionCount: len(aimodels) + 1, - Label: label, - Name: name, - Description: description, - New: MODEL_LATEST, - Type: cloudType, - Path: modelPath, - Size: modelSize, - AttachmentId: aiTask.Uuid, - RepoId: aiTask.RepoID, - UserId: ctx.User.ID, - UserRelAvatarLink: ctx.User.RelAvatarLink(), - CodeBranch: aiTask.BranchName, - CodeCommitID: aiTask.CommitID, - Engine: aiTask.EngineID, - TrainTaskInfo: string(aiTaskJson), - Accuracy: string(accuracyJson), + ID: id, + Version: version, + VersionCount: len(aimodels) + 1, + Label: label, + Name: name, + Description: description, + New: MODEL_LATEST, + Type: cloudType, + Path: modelPath, + Size: modelSize, + AttachmentId: aiTask.Uuid, + RepoId: aiTask.RepoID, + UserId: ctx.User.ID, + CodeBranch: aiTask.BranchName, + CodeCommitID: aiTask.CommitID, + Engine: aiTask.EngineID, + TrainTaskInfo: string(aiTaskJson), + Accuracy: string(accuracyJson), } err = models.SaveModelToDb(model) @@ -395,7 +394,7 @@ func ShowSingleModel(ctx *context.Context) { ctx.JSON(http.StatusOK, models) } -func queryUserName(intSlice []int64) map[int64]string { +func queryUserName(intSlice []int64) map[int64]*models.User { keys := make(map[int64]string) uniqueElements := []int64{} for _, entry := range intSlice { @@ -404,13 +403,14 @@ func queryUserName(intSlice []int64) map[int64]string { uniqueElements = append(uniqueElements, entry) } } - userNames, err := models.GetUserNamesByIDs(uniqueElements) + result := make(map[int64]*models.User) + userLists, err := models.GetUsersByIDs(uniqueElements) if err == nil { - for i, userName := range userNames { - keys[uniqueElements[i]] = userName + for i, user := range userLists { + result[uniqueElements[i]] = user } } - return keys + return result } func ShowOneVersionOtherModel(ctx *context.Context) { @@ -428,7 +428,11 @@ func ShowOneVersionOtherModel(ctx *context.Context) { userNameMap := queryUserName(userIds) for _, model := range aimodels { - model.UserName = userNameMap[model.UserId] + value := userNameMap[model.UserId] + if value != nil { + model.UserName = value.Name + model.UserRelAvatarLink = value.RelAvatarLink() + } } if len(aimodels) > 0 { @@ -500,7 +504,11 @@ func ShowModelPageInfo(ctx *context.Context) { userNameMap := queryUserName(userIds) for _, model := range modelResult { - model.UserName = userNameMap[model.UserId] + value := userNameMap[model.UserId] + if value != nil { + model.UserName = value.Name + model.UserRelAvatarLink = value.RelAvatarLink() + } } mapInterface := make(map[string]interface{})