Best-effort: try to flush pending tokens to the worldwide counter. `force` = true on status/sync commands (always attempt), false on others (only flush if stale > 30s).
(config: &mut tracedecay::user_config::UserConfig, force: bool)
| 236 | /// `force` = true on status/sync commands (always attempt), false on others |
| 237 | /// (only flush if stale > 30s). |
| 238 | pub(crate) fn try_flush(config: &mut tracedecay::user_config::UserConfig, force: bool) { |
| 239 | if config.pending_upload == 0 || !config.upload_enabled { |
| 240 | return; |
| 241 | } |
| 242 | let now = current_unix_timestamp(); |
| 243 | |
| 244 | // Cooldown: skip if last flush attempt failed less than 60s ago |
| 245 | if config.last_flush_attempt_at > config.last_upload_at |
| 246 | && elapsed_since(now, config.last_flush_attempt_at) < 60 |
| 247 | { |
| 248 | return; |
| 249 | } |
| 250 | |
| 251 | // Staleness check for non-force commands |
| 252 | if !force && elapsed_since(now, config.last_upload_at) < 30 { |
| 253 | return; |
| 254 | } |
| 255 | |
| 256 | config.last_flush_attempt_at = now; |
| 257 | if let Some(worldwide_total) = tracedecay::cloud::flush_pending(config.pending_upload) { |
| 258 | config.pending_upload = 0; |
| 259 | config.last_upload_at = now; |
| 260 | config.last_worldwide_total = worldwide_total; |
| 261 | config.last_worldwide_fetch_at = now; |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | /// Best-effort version check with 5-minute network cache. If `skip_cache` is |
| 266 | /// true, always fetches from GitHub (used during sync where the call runs in |
no test coverage detected