MCPcopy Create free account
hub / github.com/ScriptedAlchemy/tracedecay / update_global_db

Function update_global_db

src/global.rs:208–233  ·  view source on GitHub ↗

Best-effort: register this project in the user-level global DB and accumulate the token savings delta into the pending upload counter.

(cg: &TraceDecay)

Source from the content-addressed store, hash-verified

206/// Best-effort: register this project in the user-level global DB and
207/// accumulate the token savings delta into the pending upload counter.
208pub(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

Callers 2

handle_syncFunction · 0.85
init_and_indexFunction · 0.85

Calls 6

get_tokens_savedMethod · 0.80
get_project_tokensMethod · 0.80
upsertMethod · 0.80
save_if_existsMethod · 0.80
loadFunction · 0.50
project_rootMethod · 0.45

Tested by

no test coverage detected