• entities.Step とほぼ同じ、違いはslicesにして返す点のみ sqinstmtcheck // StepCollect breaks ids into chunks of size limitOpt (or default 1000), // and collects the results of the process function into a slice. // idsを分割して 1000件(デフォルト )ずつ取得した結果をスライスに収集 . func StepCollect[ID, Out any](ids []ID, process func([]ID) ([]Out, error), limitOpt ...int) ([]Out, error) { limit := 1000 if len(limitOpt) == 1 { if n := limitOpt[0]; n > 0 { limit = n } } list := make([]Out, 0, len(ids)) for chunk := range slices.Chunk(ids, limit) { res, err := process(chunk) if err != nil { return nil, err } list = append(list, res...) } return slices.Clip(list), nil
checks SQL include `IN` statement whether the query execution is chunked with `entities.Step` `entities.StepCollect` or not.", Run: run, Requires: []*analysis.Analyzer{inspect.Analyzer}, }
// `Eq` に渡された entryのvalueが配列・スライスの場合 report for _, elt := range cl.Elts { kve, ok := elt.(*ast.KeyValueExpr) if !ok { continue } if shouldChunkArrayInEqEntry(kve, stack) { key := fmt.Sprintf("%s:%v", fName, kve.Pos()) if _, ok := walked[key]; ok { continue } msg := "SQL execution include `IN` statement must be chunked. Please chunk it with `entities.Step` `entities.StepCollect`." pass.Reportf(kve.Pos(), msg) walked[key] = struct{}{} } } return true