Skip to content

Commit

Permalink
Merge pull request #2693 from actiontech/issue-2675-5
Browse files Browse the repository at this point in the history
modify: split functions and provide tools and methods
  • Loading branch information
LordofAvernus authored Oct 18, 2024
2 parents 82f5c6d + efbcc36 commit eb287d5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
13 changes: 11 additions & 2 deletions sqle/api/controller/v1/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,10 @@ func loadProjectsByWorkflows(ctx context.Context, workflows []*model.WorkflowLis
projectMap[workflow.ProjectId] = nil
}
}
return loadProjectsByProjectIds(ctx, projectIds)
}

func loadProjectsByProjectIds(ctx context.Context, projectIds []string) (projectMap map[string] /* project uid */ *dmsV1.ListProject, err error) {
// get project priority from dms
projects, _, err := dmsobject.ListProjects(ctx, controller.GetDMSServerAddress(), dmsV1.ListProjectReq{
PageSize: uint32(len(projectIds)),
Expand Down Expand Up @@ -737,11 +741,16 @@ func loadInstanceByWorkflows(ctx context.Context, workflows []*model.WorkflowLis
}
}
}
return loadInstanceByInstanceIds(ctx, instanceIdList)
}

func loadInstanceByInstanceIds(ctx context.Context, instanceIds []string) (instanceMap map[string] /* instance id */ *dmsV1.ListDBService, err error) {
// get instances from dms
instanceMap = make(map[string]*dmsV1.ListDBService)
instances, _, err := dmsobject.ListDbServices(ctx, controller.GetDMSServerAddress(), dmsV1.ListDBServiceReq{
PageSize: uint32(len(instanceIdList)),
PageSize: uint32(len(instanceIds)),
PageIndex: 1,
FilterByDBServiceIds: instanceIdList,
FilterByDBServiceIds: instanceIds,
})
if err != nil {
return nil, err
Expand Down
19 changes: 19 additions & 0 deletions sqle/utils/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,3 +407,22 @@ func TruncateAndMarkForExcelCell(s string) string {
}
return s
}

func IntersectionStringSlice(slice1, slice2 []string) []string {
// 用 map 来存储第一个切片的元素
elemMap := make(map[string]bool)
for _, v := range slice1 {
elemMap[v] = true
}

// 遍历第二个切片,找到交集
var intersection []string
for _, v := range slice2 {
if elemMap[v] {
intersection = append(intersection, v)
// 删除元素以防重复添加
delete(elemMap, v)
}
}
return intersection
}

0 comments on commit eb287d5

Please sign in to comment.