(ctx context.Context, keyword string, driver string, scope strategy_dto.Scope, target string, page int, pageSize int, filters []string, order ...string)
| 162 | } |
| 163 | |
| 164 | func (i *imlStrategyModule) Search(ctx context.Context, keyword string, driver string, scope strategy_dto.Scope, target string, page int, pageSize int, filters []string, order ...string) ([]*strategy_dto.StrategyItem, int64, error) { |
| 165 | list, total, err := i.strategyService.SearchByDriver(ctx, keyword, driver, scope.Int(), target, page, pageSize, filters, order...) |
| 166 | if err != nil { |
| 167 | return nil, 0, err |
| 168 | } |
| 169 | if len(list) < 1 { |
| 170 | return nil, 0, nil |
| 171 | } |
| 172 | strategyIds := utils.SliceToSlice(list, func(l *strategy.Strategy) string { return l.Id }) |
| 173 | commits, err := i.strategyService.ListLatestStrategyCommit(ctx, scope.String(), target, strategyIds...) |
| 174 | if err != nil { |
| 175 | return nil, 0, err |
| 176 | } |
| 177 | commitMap := utils.SliceToMapO(commits, func(c *commit.Commit[strategy.Commit]) (string, string) { return c.Data.Id, c.Data.Version }) |
| 178 | items := make([]*strategy_dto.StrategyItem, 0, len(list)) |
| 179 | countMap := make(map[string]int64) |
| 180 | c, err := i.clusterService.Get(ctx, cluster.DefaultClusterID) |
| 181 | if err == nil { |
| 182 | countMap, err = i.logService.LogCount(ctx, "loki", c.Cluster, map[string]string{ |
| 183 | "#1": fmt.Sprintf("strategy =~ \"%s\"", strings.Join(strategyIds, "|")), |
| 184 | }, 720, |
| 185 | "strategy") |
| 186 | if err != nil { |
| 187 | log.Errorf("get log count error: %v", err) |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | for _, l := range list { |
| 192 | fs := make([]*strategy_dto.Filter, 0) |
| 193 | |
| 194 | json.Unmarshal([]byte(l.Filters), &fs) |
| 195 | filterList := make([]string, 0, len(fs)) |
| 196 | for _, f := range fs { |
| 197 | info, err := strategy_filter.FilterLabel(f.Name, f.Values) |
| 198 | if err != nil { |
| 199 | log.Errorf("get filter label error: %v", err) |
| 200 | continue |
| 201 | } |
| 202 | filterList = append(filterList, fmt.Sprintf("[%s:%s]", info.Title, info.Label)) |
| 203 | } |
| 204 | item := strategy_dto.ToStrategyItem(l, commitMap[l.Id], strings.Join(filterList, ";"), countMap[l.Id]) |
| 205 | items = append(items, item) |
| 206 | } |
| 207 | sort.Slice(items, func(i, j int) bool { |
| 208 | return items[i].Priority < items[j].Priority |
| 209 | }) |
| 210 | return items, total, nil |
| 211 | } |
| 212 | |
| 213 | func (i *imlStrategyModule) Get(ctx context.Context, id string) (*strategy_dto.Strategy, error) { |
| 214 | info, err := i.strategyService.Get(ctx, id) |
nothing calls this directly
no test coverage detected