MCPcopy
hub / github.com/SpecterOps/BloodHound / cacheQueryResult

Method cacheQueryResult

cmd/api/src/queries/graph.go:903–930  ·  view source on GitHub ↗
(queryStart time.Time, cacheKey string, result graph.NodeSet)

Source from the content-addressed store, hash-verified

901}
902
903func (s *GraphQuery) cacheQueryResult(queryStart time.Time, cacheKey string, result graph.NodeSet) {
904 queryTime := time.Since(queryStart).Milliseconds()
905
906 // Only cache the result if it matches our criteria, including having a valid query name
907 if queryTime > s.SlowQueryThreshold {
908 // Using GuardedSet here even though it isn't necessary because it allows us to collect information on how often
909 // we run these queries in parallel
910 if set, sizeInBytes, err := s.Cache.GuardedSet(cacheKey, result); err != nil {
911 slog.Error(
912 "[Entity Results Cache] Failed to write results to cache for key",
913 slog.String("cache_key", cacheKey),
914 attr.Error(err),
915 )
916 } else if !set {
917 slog.Warn(
918 "[Entity Results Cache] Cache entry for query not set because it already exists",
919 slog.String("cache_key", cacheKey),
920 )
921 } else {
922 slog.Info(
923 "[Entity Results Cache] Cached slow query",
924 slog.String("cache_key", cacheKey),
925 slog.Int("size_bytes", sizeInBytes),
926 slog.Int64("query_time_ms", queryTime),
927 )
928 }
929 }
930}
931
932func runEntityQuery(ctx context.Context, db graph.Database, delegate any, node *graph.Node, skip, limit int) (graph.NodeSet, error) {
933 var result graph.NodeSet

Callers 2

Test_cacheQueryResultFunction · 0.95

Calls 6

ErrorFunction · 0.92
GuardedSetMethod · 0.80
WarnMethod · 0.80
StringMethod · 0.65
ErrorMethod · 0.45
InfoMethod · 0.45

Tested by 1

Test_cacheQueryResultFunction · 0.76