github.com/authzed/spicedb@v1.32.1-0.20240520085336-ebda56537386/pkg/datastore/stats.go (about) 1 package datastore 2 3 import ( 4 "github.com/authzed/spicedb/pkg/namespace" 5 iv1 "github.com/authzed/spicedb/pkg/proto/impl/v1" 6 ) 7 8 // ComputeObjectTypeStats creates a list of object type stats from an input list of 9 // parsed object types. 10 func ComputeObjectTypeStats(objTypes []RevisionedNamespace) []ObjectTypeStat { 11 stats := make([]ObjectTypeStat, 0, len(objTypes)) 12 13 for _, objType := range objTypes { 14 var relations, permissions uint32 15 16 for _, rel := range objType.Definition.Relation { 17 if namespace.GetRelationKind(rel) == iv1.RelationMetadata_PERMISSION { 18 permissions++ 19 } else { 20 relations++ 21 } 22 } 23 24 stats = append(stats, ObjectTypeStat{ 25 NumRelations: relations, 26 NumPermissions: permissions, 27 }) 28 } 29 30 return stats 31 }