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 commit7b1d61e9e9f0ef61be53558265ea2f3e40ef5d68Parent: 0a41196All checks have passed
Show checks
ci/buildSucceededDetails
1 changed file +1 -22
crates/forge-web-pages/src/pages/tree.rsmodified+1 -22
| @@ -1,6 +1,5 @@ | ||
| 1 | 1 | use std::collections::HashMap; |
| 2 | 2 | use std::path::{Path, PathBuf}; |
| 3 | -use std::sync::{Mutex, OnceLock}; | |
| 4 | 3 | use std::time::Duration; |
| 5 | 4 | |
| 6 | 5 | use forge_core::Repo as RepoRow; |
| @@ -67,13 +66,6 @@ pub async fn read_file(path: PathBuf, commit: String, file: String) -> Result<Op | ||
| 67 | 66 | .await??) |
| 68 | 67 | } |
| 69 | 68 | |
| 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 | - | |
| 77 | 69 | pub async fn last_commits( |
| 78 | 70 | state: &AppState, |
| 79 | 71 | path: &Path, |
| @@ -81,22 +73,9 @@ pub async fn last_commits( | ||
| 81 | 73 | dir: &str, |
| 82 | 74 | names: &[String], |
| 83 | 75 | ) -> 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 | - } | |
| 90 | 76 | let walk = history::last_commits(&state.git, path, commit, dir, names, LAST_COMMIT_WALK); |
| 91 | 77 | 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, | |
| 100 | 79 | Ok(Err(e)) => { |
| 101 | 80 | tracing::warn!(error = %e, "last-commit walk failed"); |
| 102 | 81 | HashMap::new() |