| 961 | } |
| 962 | |
| 963 | func (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 | |
| 996 | func (s *GraphQuery) runListQuery(ctx context.Context, primaryDisplayKinds graphschema.PrimaryDisplayKinds, node *graph.Node, params EntityQueryParameters, cacheEnabled bool) ([]model.PagedNodeListEntry, int, error) { |
| 997 | var ( |