(
project_id: Option<String>,
project_path: Option<String>,
since: Option<String>,
limit_sessions: usize,
dry_run: bool,
)
| 194 | const GIT_BACKFILL_ANALYTICS_LIMIT: usize = 500_000; |
| 195 | |
| 196 | async fn run_git_backfill( |
| 197 | project_id: Option<String>, |
| 198 | project_path: Option<String>, |
| 199 | since: Option<String>, |
| 200 | limit_sessions: usize, |
| 201 | dry_run: bool, |
| 202 | ) -> tracedecay::errors::Result<()> { |
| 203 | use tracedecay::sessions::git_correlation::{ |
| 204 | run_backfill, BackfillOptions, SystemGit, DEFAULT_SPAN_MERGE_GAP_SECS, |
| 205 | }; |
| 206 | |
| 207 | let project_root = resolve_cli_project_root(None, project_id, project_path).await?; |
| 208 | let since_ts = resolve_backfill_since(since.as_deref())?; |
| 209 | |
| 210 | let session_db = tracedecay::sessions::cursor::open_project_session_db(&project_root) |
| 211 | .await |
| 212 | .ok_or_else(|| tracedecay::errors::TraceDecayError::Config { |
| 213 | message: format!( |
| 214 | "could not open project session database for {}", |
| 215 | project_root.display() |
| 216 | ), |
| 217 | })?; |
| 218 | |
| 219 | // Global analytics rows are a finer-grained timestamp signal. Missing or |
| 220 | // unreadable analytics is non-fatal: the backfill still runs on session |
| 221 | // timestamps and the reflog. Scope the query to this project and the |
| 222 | // backfill window: only rows for the target project within [since_ts, now] |
| 223 | // are ever consumed, so pulling every event from every project (these |
| 224 | // stores reach tens of GB) would be pure waste. |
| 225 | let analytics_events = match tracedecay::global_db::GlobalDb::open().await { |
| 226 | Some(global) => global |
| 227 | .query_analytics_events(&tracedecay::global_db::AnalyticsEventQuery { |
| 228 | project_id: Some(tracedecay::global_db::GlobalDb::canonical_project_key( |
| 229 | &project_root, |
| 230 | )), |
| 231 | since: Some(since_ts), |
| 232 | limit: GIT_BACKFILL_ANALYTICS_LIMIT, |
| 233 | ..Default::default() |
| 234 | }) |
| 235 | .await |
| 236 | .unwrap_or_default(), |
| 237 | None => Vec::new(), |
| 238 | }; |
| 239 | |
| 240 | let opts = BackfillOptions { |
| 241 | since: since_ts, |
| 242 | limit_sessions, |
| 243 | merge_gap_secs: DEFAULT_SPAN_MERGE_GAP_SECS, |
| 244 | max_commits_per_repo: 5_000, |
| 245 | dry_run, |
| 246 | }; |
| 247 | |
| 248 | let git = SystemGit; |
| 249 | let stats = run_backfill(&session_db, &analytics_events, &git, &opts) |
| 250 | .await |
| 251 | .map_err(|err| tracedecay::errors::TraceDecayError::Config { |
| 252 | message: format!("git backfill failed: {err}"), |
| 253 | })?; |
no test coverage detected