MCPcopy Index your code
hub / github.com/SpecterOps/BloodHound / runMaybeCachedEntityQuery

Method runMaybeCachedEntityQuery

cmd/api/src/queries/graph.go:963–994  ·  view source on GitHub ↗
(ctx context.Context, node *graph.Node, params EntityQueryParameters, cacheEnabled bool)

Source from the content-addressed store, hash-verified

961}
962
963func (s *GraphQuery) runMaybeCachedEntityQuery(ctx context.Context, node *graph.Node, params EntityQueryParameters, cacheEnabled bool) (graph.NodeSet, error) {
964 var (
965 queryStart = time.Now()
966 cacheKey = fmt.Sprintf("ad-entity-query_%s_%s_%d", params.QueryName, params.ObjectID, params.RequestedType)
967
968 foundResultInCache = false
969
970 result graph.NodeSet
971 )
972
973 if cacheEnabled {
974 var err error
975 if foundResultInCache, err = s.Cache.Get(cacheKey, &result); err != nil {
976 return nil, fmt.Errorf("error getting cache entry for %s: %w", cacheKey, err)
977 }
978 }
979
980 if !cacheEnabled || !foundResultInCache {
981 // Fetch the entire result for caching purposes
982 if fetchedResult, err := runEntityQuery(ctx, s.Graph, params.ListDelegate, node, 0, 0); err != nil {
983 return nil, err
984 } else {
985 result = fetchedResult
986 }
987 }
988
989 if params.QueryName != "" && cacheEnabled && !foundResultInCache {
990 s.cacheQueryResult(queryStart, cacheKey, result)
991 }
992
993 return result, nil
994}
995
996func (s *GraphQuery) runListQuery(ctx context.Context, primaryDisplayKinds graphschema.PrimaryDisplayKinds, node *graph.Node, params EntityQueryParameters, cacheEnabled bool) ([]model.PagedNodeListEntry, int, error) {
997 var (

Callers 3

runListQueryMethod · 0.95
runCountQueryMethod · 0.95

Calls 4

cacheQueryResultMethod · 0.95
runEntityQueryFunction · 0.85
ErrorfMethod · 0.80
GetMethod · 0.65

Tested by 1