@@ -5,7 +5,7 @@ use solana_client::nonblocking::rpc_client::RpcClient;
55use solana_sdk:: { account:: Account , pubkey:: Pubkey } ;
66use tokio:: sync:: OnceCell ;
77
8- use crate :: { error:: KoraError , sanitize_error} ;
8+ use crate :: { config :: Config , error:: KoraError , sanitize_error} ;
99
1010#[ cfg( not( test) ) ]
1111use crate :: state:: get_config;
@@ -33,7 +33,8 @@ impl CacheUtil {
3333 pub async fn init ( ) -> Result < ( ) , KoraError > {
3434 let config = get_config ( ) ?;
3535
36- let pool = if CacheUtil :: is_cache_enabled ( ) {
36+ #[ allow( clippy:: needless_borrow) ]
37+ let pool = if CacheUtil :: is_cache_enabled ( & config) {
3738 let redis_url = config. kora . cache . url . as_ref ( ) . ok_or ( KoraError :: ConfigError ) ?;
3839
3940 let cfg = deadpool_redis:: Config :: from_url ( redis_url) ;
@@ -179,23 +180,19 @@ impl CacheUtil {
179180 }
180181
181182 /// Check if cache is enabled and available
182- fn is_cache_enabled ( ) -> bool {
183- match get_config ( ) {
184- Ok ( config) => config. kora . cache . enabled && config. kora . cache . url . is_some ( ) ,
185- Err ( _) => false ,
186- }
183+ fn is_cache_enabled ( config : & Config ) -> bool {
184+ config. kora . cache . enabled && config. kora . cache . url . is_some ( )
187185 }
188186
189187 /// Get account from cache with optional force refresh
190188 pub async fn get_account (
189+ config : & Config ,
191190 rpc_client : & RpcClient ,
192191 pubkey : & Pubkey ,
193192 force_refresh : bool ,
194193 ) -> Result < Account , KoraError > {
195- let config = get_config ( ) ?;
196-
197194 // If cache is disabled or force refresh is requested, go directly to RPC
198- if !CacheUtil :: is_cache_enabled ( ) {
195+ if !CacheUtil :: is_cache_enabled ( config ) {
199196 return Self :: get_account_from_rpc ( rpc_client, pubkey) . await ;
200197 }
201198
@@ -264,7 +261,8 @@ mod tests {
264261 async fn test_is_cache_enabled_disabled ( ) {
265262 let _m = ConfigMockBuilder :: new ( ) . with_cache_enabled ( false ) . build_and_setup ( ) ;
266263
267- assert ! ( !CacheUtil :: is_cache_enabled( ) ) ;
264+ let config = get_config ( ) . unwrap ( ) ;
265+ assert ! ( !CacheUtil :: is_cache_enabled( & config) ) ;
268266 }
269267
270268 #[ tokio:: test]
@@ -275,7 +273,8 @@ mod tests {
275273 . build_and_setup ( ) ;
276274
277275 // Without URL, cache should be disabled
278- assert ! ( !CacheUtil :: is_cache_enabled( ) ) ;
276+ let config = get_config ( ) . unwrap ( ) ;
277+ assert ! ( !CacheUtil :: is_cache_enabled( & config) ) ;
279278 }
280279
281280 #[ tokio:: test]
@@ -286,7 +285,8 @@ mod tests {
286285 . build_and_setup ( ) ;
287286
288287 // Give time for config to be set up
289- assert ! ( CacheUtil :: is_cache_enabled( ) ) ;
288+ let config = get_config ( ) . unwrap ( ) ;
289+ assert ! ( CacheUtil :: is_cache_enabled( & config) ) ;
290290 }
291291
292292 #[ tokio:: test]
@@ -336,7 +336,8 @@ mod tests {
336336
337337 let rpc_client = RpcMockBuilder :: new ( ) . with_account_info ( & expected_account) . build ( ) ;
338338
339- let result = CacheUtil :: get_account ( & rpc_client, & pubkey, false ) . await ;
339+ let config = get_config ( ) . unwrap ( ) ;
340+ let result = CacheUtil :: get_account ( & config, & rpc_client, & pubkey, false ) . await ;
340341
341342 assert ! ( result. is_ok( ) ) ;
342343 let account = result. unwrap ( ) ;
@@ -355,7 +356,8 @@ mod tests {
355356 let rpc_client = RpcMockBuilder :: new ( ) . with_account_info ( & expected_account) . build ( ) ;
356357
357358 // force_refresh = true should always go to RPC
358- let result = CacheUtil :: get_account ( & rpc_client, & pubkey, true ) . await ;
359+ let config = get_config ( ) . unwrap ( ) ;
360+ let result = CacheUtil :: get_account ( & config, & rpc_client, & pubkey, true ) . await ;
359361
360362 assert ! ( result. is_ok( ) ) ;
361363 let account = result. unwrap ( ) ;
0 commit comments