| 901 | } |
| 902 | |
| 903 | func (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 | |
| 932 | func runEntityQuery(ctx context.Context, db graph.Database, delegate any, node *graph.Node, skip, limit int) (graph.NodeSet, error) { |
| 933 | var result graph.NodeSet |