github.com/authzed/spicedb@v1.32.1-0.20240520085336-ebda56537386/internal/namespace/annotate.go (about)

     1  package namespace
     2  
     3  import "github.com/authzed/spicedb/pkg/typesystem"
     4  
     5  // AnnotateNamespace annotates the namespace in the type system with computed aliasing and cache key
     6  // metadata for more efficient dispatching.
     7  func AnnotateNamespace(ts *typesystem.ValidatedNamespaceTypeSystem) error {
     8  	aliases, aerr := computePermissionAliases(ts)
     9  	if aerr != nil {
    10  		return aerr
    11  	}
    12  
    13  	cacheKeys, cerr := computeCanonicalCacheKeys(ts, aliases)
    14  	if cerr != nil {
    15  		return cerr
    16  	}
    17  
    18  	for _, rel := range ts.Namespace().Relation {
    19  		if alias, ok := aliases[rel.Name]; ok {
    20  			rel.AliasingRelation = alias
    21  		}
    22  
    23  		if cacheKey, ok := cacheKeys[rel.Name]; ok {
    24  			rel.CanonicalCacheKey = cacheKey
    25  		}
    26  	}
    27  
    28  	return nil
    29  }