Best-effort: register this project in the user-level global DB and accumulate the token savings delta into the pending upload counter.
(cg: &TraceDecay)
| 206 | /// Best-effort: register this project in the user-level global DB and |
| 207 | /// accumulate the token savings delta into the pending upload counter. |
| 208 | pub(crate) async fn update_global_db(cg: &TraceDecay) { |
| 209 | if !tracedecay::user_config::UserConfig::exists() { |
| 210 | return; |
| 211 | } |
| 212 | let tokens = match cg.get_tokens_saved().await { |
| 213 | Ok(tokens) => tokens, |
| 214 | Err(err) => { |
| 215 | eprintln!( |
| 216 | "[tracedecay] failed to read tokens-saved counter for {}: {err}", |
| 217 | cg.project_root().display() |
| 218 | ); |
| 219 | return; |
| 220 | } |
| 221 | }; |
| 222 | if let Some(gdb) = tracedecay::global_db::GlobalDb::open().await { |
| 223 | let previous = gdb.get_project_tokens(cg.project_root()).await; |
| 224 | gdb.upsert(cg.project_root(), tokens).await; |
| 225 | |
| 226 | // Accumulate delta into pending upload |
| 227 | if tokens > previous { |
| 228 | let mut config = tracedecay::user_config::UserConfig::load(); |
| 229 | config.pending_upload += tokens - previous; |
| 230 | config.save_if_exists(); |
| 231 | } |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | /// Best-effort: try to flush pending tokens to the worldwide counter. |
| 236 | /// `force` = true on status/sync commands (always attempt), false on others |
no test coverage detected