Commit

A last-commits walk runs to the end unless asked for a budget; the page bounds its own wait

syntaqxcommitted Parent4c64095Browse files
2 files+7−40/2 viewed
+4−0
576576 pub git_ref: Option<String>,
577577 #[serde(default)]
578578 pub tree_path: String,
579+ /// Answer within this many milliseconds with what was found, not kept;
580+ /// absent, the walk runs to the end and is kept.
581+ #[serde(default)]
582+ pub budget_ms: Option<u64>,
579583 }
580584
581585 /// An entry of a directory and the commit that last changed it.
+3−4
6060 const MAX_ANCESTRY: u32 = 1000;
6161 /// The most tags a repository's Tags page reads and lists.
6262 const MAX_TAGS_READ: usize = 100;
63−/// How long a last-commits walk may take before it answers with what it has.
64−const LAST_COMMITS_BUDGET_MS: u64 = 2_500;
6563
6664 /// One path segment, percent-encoded for a cache key.
6765 fn urlencoding_segment(segment: &str) -> String {
772770 return Ok(Outcome::Ok(found));
773771 }
774772 }
775− // A page waits on this: past the budget, what was found so far, not kept.
773+ // Asked with a budget: past it, what was found so far, not kept.
776774 let started = worker::Date::now().as_millis();
777− let out_of_time = move || worker::Date::now().as_millis().saturating_sub(started) > LAST_COMMITS_BUDGET_MS;
775+ let budget = a.budget_ms;
776+ let out_of_time = move || budget.is_some_and(|budget| worker::Date::now().as_millis().saturating_sub(started) > budget);
778777 let (entries, complete) = last_commits::last_commits(&git, &head.hash, &a.tree_path, &out_of_time).await?;
779778 let stopped = out_of_time();
780779 let found = g1t_contracts::repos::LastCommits { entries, complete };