@@ -6,6 +6,7 @@ use crate::pipeline::normalize::GraphQLNormalizationPayload;
66use crate :: pipeline:: progressive_override:: { RequestOverrideContext , StableOverrideContext } ;
77use crate :: shared_state:: RouterSharedState ;
88use hive_router_query_planner:: planner:: plan_nodes:: QueryPlan ;
9+ use hive_router_query_planner:: planner:: PlannerError ;
910use hive_router_query_planner:: utils:: cancellation:: CancellationToken ;
1011use ntex:: web:: HttpRequest ;
1112use xxhash_rust:: xxh3:: Xxh3 ;
@@ -22,36 +23,36 @@ pub async fn plan_operation_with_cache(
2223 StableOverrideContext :: new ( & app_state. planner . supergraph , request_override_context) ;
2324
2425 let filtered_operation_for_plan = & normalized_operation. operation_for_plan ;
25- let plan_cache_key =
26- calculate_cache_key ( filtered_operation_for_plan. hash ( ) , & stable_override_context) ;
27- let is_pure_introspection = filtered_operation_for_plan. selection_set . is_empty ( )
28- && normalized_operation. operation_for_introspection . is_some ( ) ;
2926
30- let plan_result = app_state
31- . plan_cache
32- . try_get_with ( plan_cache_key, async move {
33- if is_pure_introspection {
34- return Ok ( Arc :: new ( QueryPlan {
35- kind : "QueryPlan" . to_string ( ) ,
36- node : None ,
37- } ) ) ;
38- }
39-
40- app_state
41- . planner
42- . plan_from_normalized_operation (
27+ if !app_state. router_config . query_planner . cache . enabled {
28+ get_plan (
29+ app_state,
30+ filtered_operation_for_plan,
31+ normalized_operation,
32+ request_override_context,
33+ cancellation_token,
34+ )
35+ . map ( Arc :: new)
36+ . map_err ( Arc :: new)
37+ } else {
38+ let plan_cache_key =
39+ calculate_cache_key ( filtered_operation_for_plan. hash ( ) , & stable_override_context) ;
40+
41+ app_state
42+ . plan_cache
43+ . try_get_with ( plan_cache_key, async move {
44+ get_plan (
45+ app_state,
4346 filtered_operation_for_plan,
44- ( & request_override_context. clone ( ) ) . into ( ) ,
47+ normalized_operation,
48+ request_override_context,
4549 cancellation_token,
4650 )
4751 . map ( Arc :: new)
48- } )
49- . await ;
50-
51- match plan_result {
52- Ok ( plan) => Ok ( plan) ,
53- Err ( e) => Err ( req. new_pipeline_error ( PipelineErrorVariant :: PlannerError ( e. clone ( ) ) ) ) ,
52+ } )
53+ . await
5454 }
55+ . map_err ( |err| req. new_pipeline_error ( PipelineErrorVariant :: PlannerError ( err) ) )
5556}
5657
5758#[ inline]
@@ -61,3 +62,27 @@ fn calculate_cache_key(operation_hash: u64, context: &StableOverrideContext) ->
6162 context. hash ( & mut hasher) ;
6263 hasher. finish ( )
6364}
65+
66+ #[ inline]
67+ fn get_plan (
68+ app_state : & Arc < RouterSharedState > ,
69+ filtered_operation_for_plan : & hive_router_query_planner:: ast:: operation:: OperationDefinition ,
70+ normalized_operation : & Arc < GraphQLNormalizationPayload > ,
71+ request_override_context : & RequestOverrideContext ,
72+ cancellation_token : & CancellationToken ,
73+ ) -> Result < QueryPlan , PlannerError > {
74+ let is_pure_introspection = filtered_operation_for_plan. selection_set . is_empty ( )
75+ && normalized_operation. operation_for_introspection . is_some ( ) ;
76+ if is_pure_introspection {
77+ return Ok ( QueryPlan {
78+ kind : "QueryPlan" . to_string ( ) ,
79+ node : None ,
80+ } ) ;
81+ }
82+
83+ app_state. planner . plan_from_normalized_operation (
84+ filtered_operation_for_plan,
85+ ( & request_override_context. clone ( ) ) . into ( ) ,
86+ cancellation_token,
87+ )
88+ }
0 commit comments