@@ -546,8 +546,6 @@ fn test_clear_stale_call_cache() {
546546 let call: [ u8 ; 6 ] = [ 1 , 2 , 3 , 4 , 5 , 6 ] ;
547547 let return_value: [ u8 ; 3 ] = [ 7 , 8 , 9 ] ;
548548
549- let mut conn = PRIMARY_POOL . get ( ) . await . unwrap ( ) ;
550-
551549 // Insert a call cache entry, otherwise it will hit an early return and won't test all queries
552550 let call = call:: Request :: new ( address, call. to_vec ( ) , 0 ) ;
553551 chain_store
@@ -569,30 +567,37 @@ fn test_clear_stale_call_cache() {
569567 assert ! ( ret. is_some( ) ) ;
570568
571569 // Now we need to update the accessed_at timestamp to be stale, so it gets deleted
572- // Get namespace from chains table
573- let namespace: String = diesel:: sql_query ( format ! (
574- "SELECT namespace FROM public.chains WHERE name = '{}'" ,
575- chain_store. chain
576- ) )
577- . get_result :: < Namespace > ( & mut conn)
578- . await
579- . unwrap ( )
580- . namespace ;
570+ // Get namespace from chains table in the primary
571+ let namespace: String = {
572+ let mut conn = PRIMARY_POOL . get ( ) . await . unwrap ( ) ;
573+ diesel:: sql_query ( format ! (
574+ "SELECT namespace FROM public.chains WHERE name = '{}'" ,
575+ chain_store. chain
576+ ) )
577+ . get_result :: < Namespace > ( & mut conn)
578+ . await
579+ . unwrap ( )
580+ . namespace
581+ } ;
581582
582583 // Determine the correct meta table name
583584 let meta_table: String = match namespace. as_str ( ) {
584585 "public" => "eth_call_meta" . to_owned ( ) ,
585586 _ => format ! ( "{namespace}.call_meta" ) ,
586587 } ;
587588
588- // Update accessed_at to be 8 days ago, so it's stale for a 7 day threshold
589- let _ = diesel:: sql_query ( format ! (
590- "UPDATE {meta_table} SET accessed_at = NOW() - INTERVAL '8 days' WHERE contract_address = $1"
591- ) ) . bind :: < diesel:: sql_types:: Bytea , _ > ( address. as_bytes ( ) )
592- . execute ( & mut conn)
593- . await
594- . unwrap ( ) ;
595-
589+ // Update accessed_at to be 8 days ago, so it's stale for a 7 day
590+ // threshold in the shard where the chain lives
591+ {
592+ let mut conn = chain_store. get_conn_for_test ( ) . await . unwrap ( ) ;
593+ diesel:: sql_query ( format ! (
594+ "UPDATE {meta_table} SET accessed_at = NOW() - INTERVAL '8 days' WHERE contract_address = $1"
595+ ) )
596+ . bind :: < diesel:: sql_types:: Bytea , _ > ( address. as_bytes ( ) )
597+ . execute ( & mut conn)
598+ . await
599+ . unwrap ( ) ;
600+ }
596601 let result = chain_store. clear_stale_call_cache ( 7 , None ) . await ;
597602 assert ! ( result. is_ok( ) ) ;
598603
0 commit comments