forge
Explore
Log in

Don't you dare go Hollow

Revert "⚡ perf: a tree's last-commit walk is cached per commit; the code page renders in 5 ms instead of 38 ms after its first view"

Browse files at this commit

7b1d61e9e9f0ef61be53558265ea2f3e40ef5d68Ahmet Kaan GümüşParent: 0a41196
Checks pending
Show checks
This reverts commit ed35470096ab56222b613ee2c5138d05557e1902.
crates/forge-web-pages/src/pages/tree.rsmodified+1 -22
@@ -1,6 +1,5 @@
11 use std::collections::HashMap;
22 use std::path::{Path, PathBuf};
3-use std::sync::{Mutex, OnceLock};
43 use std::time::Duration;
54
65 use forge_core::Repo as RepoRow;
@@ -67,13 +66,6 @@ pub async fn read_file(path: PathBuf, commit: String, file: String) -> Result<Op
6766 .await??)
6867 }
6968
70-type LastCommitCache = Mutex<HashMap<(PathBuf, String), (String, HashMap<String, CommitInfo>)>>;
71-
72-fn last_commit_cache() -> &'static LastCommitCache {
73- static CACHE: OnceLock<LastCommitCache> = OnceLock::new();
74- CACHE.get_or_init(|| Mutex::new(HashMap::new()))
75-}
76-
7769 pub async fn last_commits(
7870 state: &AppState,
7971 path: &Path,
@@ -81,22 +73,9 @@ pub async fn last_commits(
8173 dir: &str,
8274 names: &[String],
8375 ) -> HashMap<String, CommitInfo> {
84- let key = (path.to_path_buf(), dir.to_owned());
85- if let Some((at, map)) = last_commit_cache().lock().expect("last-commit cache").get(&key)
86- && at == commit
87- {
88- return map.clone();
89- }
9076 let walk = history::last_commits(&state.git, path, commit, dir, names, LAST_COMMIT_WALK);
9177 match tokio::time::timeout(LAST_COMMIT_TIMEOUT, walk).await {
92- Ok(Ok(map)) => {
93- let mut cache = last_commit_cache().lock().expect("last-commit cache");
94- if cache.len() >= 1024 {
95- cache.clear();
96- }
97- cache.insert(key, (commit.to_owned(), map.clone()));
98- map
99- }
78+ Ok(Ok(map)) => map,
10079 Ok(Err(e)) => {
10180 tracing::warn!(error = %e, "last-commit walk failed");
10281 HashMap::new()