classifyComplexity determines query complexity based on AST characteristics.
(tree *ast.AST)
| 188 | |
| 189 | // classifyComplexity determines query complexity based on AST characteristics. |
| 190 | func classifyComplexity(tree *ast.AST) string { |
| 191 | if tree == nil || len(tree.Statements) == 0 { |
| 192 | return ComplexitySimple |
| 193 | } |
| 194 | |
| 195 | complexityScore := 0 |
| 196 | |
| 197 | for _, stmt := range tree.Statements { |
| 198 | complexityScore += statementComplexity(stmt) |
| 199 | } |
| 200 | |
| 201 | switch { |
| 202 | case complexityScore >= 5: |
| 203 | return ComplexityComplex |
| 204 | case complexityScore >= 2: |
| 205 | return ComplexityModerate |
| 206 | default: |
| 207 | return ComplexitySimple |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | // statementComplexity scores the complexity of a single statement. |
| 212 | func statementComplexity(stmt ast.Statement) int { |