fix: Optimize the GetDraftIntelligenceList function and reduce the use of goroutine (#171)
This commit is contained in:
parent
2ee3fa68ab
commit
db7c95885d
|
|
@ -76,15 +76,14 @@ func (s *SearchApplicationService) GetDraftIntelligenceList(ctx context.Context,
|
||||||
intelligenceDataList := make([]*intelligence.IntelligenceData, len(searchResp.Data))
|
intelligenceDataList := make([]*intelligence.IntelligenceData, len(searchResp.Data))
|
||||||
|
|
||||||
logs.CtxDebugf(ctx, "[GetDraftIntelligenceList] searchResp.Data: %v", conv.DebugJsonToStr(searchResp.Data))
|
logs.CtxDebugf(ctx, "[GetDraftIntelligenceList] searchResp.Data: %v", conv.DebugJsonToStr(searchResp.Data))
|
||||||
|
if len(searchResp.Data) > 1 {
|
||||||
for idx := range searchResp.Data {
|
for idx := range searchResp.Data[1:] {
|
||||||
data := searchResp.Data[idx]
|
index := idx + 1
|
||||||
index := idx
|
data := searchResp.Data[index]
|
||||||
tasks.Go(func() error {
|
tasks.Go(func() error {
|
||||||
info, err := s.packIntelligenceData(ctx, data)
|
info, err := s.packIntelligenceData(ctx, data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logs.CtxErrorf(ctx, "[packIntelligenceData] failed id %v, type %d , name %s, err: %v", data.ID, data.Type, data.GetName(), err)
|
logs.CtxErrorf(ctx, "[packIntelligenceData] failed id %v, type %d , name %s, err: %v", data.ID, data.Type, data.GetName(), err)
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -94,8 +93,21 @@ func (s *SearchApplicationService) GetDraftIntelligenceList(ctx context.Context,
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
_ = tasks.Wait()
|
if len(searchResp.Data) != 0 {
|
||||||
|
info, err := s.packIntelligenceData(ctx, searchResp.Data[0])
|
||||||
|
if err != nil {
|
||||||
|
logs.CtxErrorf(ctx, "[packIntelligenceData] failed id %v, type %d , name %s, err: %v", searchResp.Data[0].ID, searchResp.Data[0].Type, searchResp.Data[0].GetName(), err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
lock.Lock()
|
||||||
|
intelligenceDataList[0] = info
|
||||||
|
lock.Unlock()
|
||||||
|
}
|
||||||
|
err = tasks.Wait()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
filterDataList := make([]*intelligence.IntelligenceData, 0)
|
filterDataList := make([]*intelligence.IntelligenceData, 0)
|
||||||
for _, data := range intelligenceDataList {
|
for _, data := range intelligenceDataList {
|
||||||
if data != nil {
|
if data != nil {
|
||||||
|
|
|
||||||
|
|
@ -86,9 +86,10 @@ func (s *SearchApplicationService) LibraryResourceList(ctx context.Context, req
|
||||||
lock := sync.Mutex{}
|
lock := sync.Mutex{}
|
||||||
tasks := taskgroup.NewUninterruptibleTaskGroup(ctx, 10)
|
tasks := taskgroup.NewUninterruptibleTaskGroup(ctx, 10)
|
||||||
resources := make([]*common.ResourceInfo, len(searchResp.Data))
|
resources := make([]*common.ResourceInfo, len(searchResp.Data))
|
||||||
for idx := range searchResp.Data {
|
if len(searchResp.Data) > 1 {
|
||||||
v := searchResp.Data[idx]
|
for idx := range searchResp.Data[1:] {
|
||||||
index := idx
|
index := idx + 1
|
||||||
|
v := searchResp.Data[index]
|
||||||
tasks.Go(func() error {
|
tasks.Go(func() error {
|
||||||
ri, err := s.packResource(ctx, v)
|
ri, err := s.packResource(ctx, v)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -103,8 +104,21 @@ func (s *SearchApplicationService) LibraryResourceList(ctx context.Context, req
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if len(searchResp.Data) != 0 {
|
||||||
|
ri, err := s.packResource(ctx, searchResp.Data[0])
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
lock.Lock()
|
||||||
|
resources[0] = ri
|
||||||
|
lock.Unlock()
|
||||||
|
}
|
||||||
|
err = tasks.Wait()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
_ = tasks.Wait()
|
|
||||||
filterResource := make([]*common.ResourceInfo, 0)
|
filterResource := make([]*common.ResourceInfo, 0)
|
||||||
for _, res := range resources {
|
for _, res := range resources {
|
||||||
if res == nil {
|
if res == nil {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue