Browse Source

Merge pull request '解决#1005 修改用户名之后,头像不显示的问题。' (#1091) from zouap_static into V20211213

Reviewed-on: https://git.openi.org.cn/OpenI/aiforge/pulls/1091
Reviewed-by: lewis <747342561@qq.com>
tags/v1.21.12.1^2
lewis 4 years ago
parent
commit
f049413747
2 changed files with 35 additions and 27 deletions
  1. +1
    -1
      models/ai_model_manage.go
  2. +34
    -26
      routers/repo/ai_model_manage.go

+ 1
- 1
models/ai_model_manage.go View File

@@ -31,7 +31,7 @@ type AiModelManage struct {
CodeCommitID string `xorm:"NULL"` CodeCommitID string `xorm:"NULL"`
UserId int64 `xorm:"NOT NULL"` UserId int64 `xorm:"NOT NULL"`
UserName string UserName string
UserRelAvatarLink string `xorm:"NULL"`
UserRelAvatarLink string
TrainTaskInfo string `xorm:"text NULL"` TrainTaskInfo string `xorm:"text NULL"`
CreatedUnix timeutil.TimeStamp `xorm:"created"` CreatedUnix timeutil.TimeStamp `xorm:"created"`
UpdatedUnix timeutil.TimeStamp `xorm:"updated"` UpdatedUnix timeutil.TimeStamp `xorm:"updated"`


+ 34
- 26
routers/repo/ai_model_manage.go View File

@@ -71,25 +71,24 @@ func saveModelByParameters(jobId string, versionName string, name string, versio
aiTaskJson, _ := json.Marshal(aiTask) aiTaskJson, _ := json.Marshal(aiTask)


model := &models.AiModelManage{ 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) err = models.SaveModelToDb(model)
@@ -395,7 +394,7 @@ func ShowSingleModel(ctx *context.Context) {
ctx.JSON(http.StatusOK, models) 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) keys := make(map[int64]string)
uniqueElements := []int64{} uniqueElements := []int64{}
for _, entry := range intSlice { for _, entry := range intSlice {
@@ -404,13 +403,14 @@ func queryUserName(intSlice []int64) map[int64]string {
uniqueElements = append(uniqueElements, entry) uniqueElements = append(uniqueElements, entry)
} }
} }
userNames, err := models.GetUserNamesByIDs(uniqueElements)
result := make(map[int64]*models.User)
userLists, err := models.GetUsersByIDs(uniqueElements)
if err == nil { 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) { func ShowOneVersionOtherModel(ctx *context.Context) {
@@ -428,7 +428,11 @@ func ShowOneVersionOtherModel(ctx *context.Context) {
userNameMap := queryUserName(userIds) userNameMap := queryUserName(userIds)


for _, model := range aimodels { 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 { if len(aimodels) > 0 {
@@ -504,7 +508,11 @@ func ShowModelPageInfo(ctx *context.Context) {


userNameMap := queryUserName(userIds) userNameMap := queryUserName(userIds)
for _, model := range modelResult { 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{}) mapInterface := make(map[string]interface{})


Loading…
Cancel
Save