queryopt

package
v1.53.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 11, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyOptimizations

func ApplyOptimizations(co query.CanonicalOutline, opts []Optimizer, params RequestParams) (query.CanonicalOutline, error)

ApplyOptimizations sorts the given optimizers by descending Priority (higher priority runs first), and applies their transforms to the outline. Nodes that survive mutation unchanged keep their existing IDs. Newly synthesized nodes (ID==0) receive fresh IDs via query.FillMissingNodeIDs. The returned CanonicalOutline is ready to compile.

func MustRegisterOptimization

func MustRegisterOptimization(opt Optimizer)

Types

type Optimizer

type Optimizer struct {
	Name        string
	Description string
	// NewTransform creates a whole-tree transformation for this optimizer,
	// optionally using request-specific parameters. Each transform typically
	// calls query.MutateOutline internally with its own mutations.
	NewTransform func(RequestParams) OutlineTransform
	// Priority controls the order in which optimizations are applied.
	// Higher values run first.
	Priority int
}

Optimizer describes a single named outline optimization.

func GetOptimization

func GetOptimization(name string) (Optimizer, error)

func OptimizersForRequest added in v1.53.0

func OptimizersForRequest(params RequestParams) []Optimizer

OptimizersForRequest returns the list of optimizers to apply for the given request parameters. The selection logic lives here (in the queryopt package) rather than in the service layer, so that optimizer safety constraints are enforced centrally.

alias-chain-collapse is included when safe:

  • Always safe for Check (self-edge is a redundant fallback in alias chains)
  • Safe for IterResources/IterSubjects when SubjectRelation is "..." (ellipsis never matches any alias relation, so no self-edge is triggered)
  • NOT safe for IterResources/IterSubjects when SubjectRelation is a specific name, as it could match an inner alias but not the outer — collapsing would change self-edge behavior.

type OutlineTransform

type OutlineTransform func(query.Outline) query.Outline

OutlineTransform is a function that transforms an entire outline tree. Each optimizer produces one of these, and they are applied sequentially.

type RequestParams

type RequestParams struct {
	// Operation identifies which query operation is being planned.
	// Used by the selection function to determine which optimizers are safe.
	Operation query.Operation
	// SubjectType is the object type of the subject/filter.
	SubjectType string
	// SubjectRelation is the relation on the subject.
	// Set to "..." for ellipsis subjects (e.g. user:...), "" for bare subjects,
	// or a specific relation name (e.g. "viewer").
	SubjectRelation string
}

RequestParams holds request-specific values available to optimizations and optimizer selection. Static (schema-level) optimizations ignore these; request-parameterized optimizations (e.g. reachability pruning) use them to tailor their behavior. The selection function uses them to decide which optimizers to include.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL