@@ -34,11 +34,7 @@ impl TrendingCache {
3434 cache_dir. push ( ".gittype" ) ;
3535 cache_dir. push ( "trending_cache" ) ;
3636
37- let ttl_seconds = if let Ok ( config_manager) = crate :: config:: ConfigManager :: new ( ) {
38- config_manager. get_config ( ) . trending . cache_ttl_minutes * 60
39- } else {
40- 300 // 5 minutes default
41- } ;
37+ let ttl_seconds = 300 ; // 5 minutes
4238
4339 Self {
4440 cache_dir,
@@ -57,11 +53,11 @@ impl TrendingCache {
5753
5854 let current_time = SystemTime :: now ( )
5955 . duration_since ( UNIX_EPOCH )
60- . unwrap ( )
56+ . unwrap_or_else ( |_| Duration :: from_secs ( 0 ) )
6157 . as_secs ( ) ;
6258
6359 // Check if cache is still valid
64- if current_time - cache_data. timestamp < self . ttl_seconds {
60+ if current_time. saturating_sub ( cache_data. timestamp ) < self . ttl_seconds {
6561 Some ( cache_data. repositories )
6662 } else {
6763 // Remove expired cache file
@@ -75,7 +71,7 @@ impl TrendingCache {
7571
7672 let current_time = SystemTime :: now ( )
7773 . duration_since ( UNIX_EPOCH )
78- . unwrap ( )
74+ . unwrap_or_else ( |_| Duration :: from_secs ( 0 ) )
7975 . as_secs ( ) ;
8076
8177 let cache_data = TrendingCacheData {
@@ -97,14 +93,14 @@ impl TrendingCache {
9793
9894 let current_time = SystemTime :: now ( )
9995 . duration_since ( UNIX_EPOCH )
100- . unwrap ( )
96+ . unwrap_or_else ( |_| Duration :: from_secs ( 0 ) )
10197 . as_secs ( ) ;
10298
10399 if let Ok ( entries) = fs:: read_dir ( & self . cache_dir ) {
104100 for entry in entries. flatten ( ) {
105101 if let Ok ( content) = fs:: read_to_string ( entry. path ( ) ) {
106102 if let Ok ( cache_data) = serde_json:: from_str :: < TrendingCacheData > ( & content) {
107- if current_time - cache_data. timestamp >= self . ttl_seconds {
103+ if current_time. saturating_sub ( cache_data. timestamp ) >= self . ttl_seconds {
108104 let _ = fs:: remove_file ( entry. path ( ) ) ;
109105 }
110106 }
@@ -151,6 +147,9 @@ pub async fn run_trending(
151147 command : None ,
152148 } ;
153149 return crate :: cli:: commands:: run_game_session ( cli) ;
150+ } else {
151+ eprintln ! ( "⚠️ Repository '{}' not found in trending list" , name) ;
152+ return Ok ( ( ) ) ;
154153 }
155154 } else if language. is_some ( ) {
156155 // Language provided - show repositories directly
@@ -221,11 +220,7 @@ pub async fn fetch_trending_repositories_cached(
221220 TRENDING_CACHE . cleanup_expired ( ) ;
222221
223222 // Rate limiting: wait a bit between API calls to be respectful
224- let rate_limit_ms = if let Ok ( config_manager) = crate :: config:: ConfigManager :: new ( ) {
225- config_manager. get_config ( ) . trending . rate_limit_ms
226- } else {
227- 100 // default 100ms
228- } ;
223+ let rate_limit_ms = 100 ; // 100ms
229224 tokio:: time:: sleep ( Duration :: from_millis ( rate_limit_ms) ) . await ;
230225
231226 // Fetch from API
@@ -281,6 +276,7 @@ async fn fetch_trending_repositories(
281276 . get ( & url)
282277 . header ( "User-Agent" , "gittype" )
283278 . header ( "Accept" , "application/json" )
279+ . timeout ( Duration :: from_secs ( 10 ) )
284280 . send ( )
285281 . await ?;
286282
0 commit comments