MCPcopy Index your code
hub / github.com/bytebase/bytebase / buildDependencyEdges

Function buildDependencyEdges

backend/plugin/parser/pg/query_span_loader.go:341–393  ·  view source on GitHub ↗

buildDependencyEdges returns a map from each object's key to the keys of objects it depends on. Only edges whose target actually exists in the collected set are recorded; references to unknown objects become no-ops (the install will fail and trigger pseudo).

(objects []*objectEntry, index map[string]*objectEntry)

Source from the content-addressed store, hash-verified

339// collected set are recorded; references to unknown objects become no-ops
340// (the install will fail and trigger pseudo).
341func buildDependencyEdges(objects []*objectEntry, index map[string]*objectEntry) map[string][]string {
342 edges := make(map[string][]string, len(objects))
343 for _, obj := range objects {
344 var deps []string
345 // Every non-schema object depends on its schema.
346 if obj.kind != kindSchema {
347 if key := "schema:" + obj.schema; index[key] != nil {
348 deps = append(deps, key)
349 }
350 }
351 switch obj.kind {
352 case kindTable:
353 for _, col := range obj.tableMeta.Columns {
354 for _, ref := range extractUserTypeRefs(col.Type) {
355 if k := typeRefKey(ref); index[k] != nil {
356 deps = append(deps, k)
357 }
358 }
359 }
360 case kindView:
361 for _, dep := range obj.viewMeta.DependencyColumns {
362 if k := relationKey(dep.Schema, dep.Table); index[k] != nil {
363 deps = append(deps, k)
364 }
365 }
366 case kindMatView:
367 for _, dep := range obj.matViewMeta.DependencyColumns {
368 if k := relationKey(dep.Schema, dep.Table); index[k] != nil {
369 deps = append(deps, k)
370 }
371 }
372 case kindFunction:
373 argTypes, _ := parseFunctionSignatureArgTypes(obj.funcMeta.Signature)
374 for _, at := range argTypes {
375 for _, ref := range extractUserTypeRefs(at) {
376 if k := typeRefKey(ref); index[k] != nil {
377 deps = append(deps, k)
378 }
379 }
380 }
381 case kindSchema, kindEnum:
382 // Schemas have no outgoing edges (they are the top of the graph).
383 // Enums depend only on their schema, already captured above.
384 default:
385 // Unknown kinds contribute no edges; install will surface the
386 // problem at real-install time.
387 }
388 if len(deps) > 0 {
389 edges[obj.key()] = dedupStrings(deps)
390 }
391 }
392 return edges
393}
394
395func typeRefKey(r UserTypeRef) string {
396 return "type:" + r.Schema + "." + r.Name

Callers 1

topoSortObjectsFunction · 0.85

Calls 6

extractUserTypeRefsFunction · 0.85
typeRefKeyFunction · 0.85
relationKeyFunction · 0.85
dedupStringsFunction · 0.85
keyMethod · 0.45

Tested by

no test coverage detected