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
All checks have passed
Show checks
This reverts commit ed35470096ab56222b613ee2c5138d05557e1902.
crates/forge-web-pages/src/pages/tree.rsmodified+1 -22
@@ -1,6 +1,5 @@
1 use std::collections::HashMap;1 use std::collections::HashMap;
2 use std::path::{Path, PathBuf};2 use std::path::{Path, PathBuf};
3-use std::sync::{Mutex, OnceLock};
4 use std::time::Duration;3 use std::time::Duration;
5 4
6 use forge_core::Repo as RepoRow;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 .await??)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 pub async fn last_commits(69 pub async fn last_commits(
78 state: &AppState,70 state: &AppState,
79 path: &Path,71 path: &Path,
@@ -81,22 +73,9 @@ pub async fn last_commits(
81 dir: &str,73 dir: &str,
82 names: &[String],74 names: &[String],
83 ) -> HashMap<String, CommitInfo> {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 let walk = history::last_commits(&state.git, path, commit, dir, names, LAST_COMMIT_WALK);76 let walk = history::last_commits(&state.git, path, commit, dir, names, LAST_COMMIT_WALK);
91 match tokio::time::timeout(LAST_COMMIT_TIMEOUT, walk).await {77 match tokio::time::timeout(LAST_COMMIT_TIMEOUT, walk).await {
92- Ok(Ok(map)) => {78+ Ok(Ok(map)) => 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- }
100 Ok(Err(e)) => {79 Ok(Err(e)) => {
101 tracing::warn!(error = %e, "last-commit walk failed");80 tracing::warn!(error = %e, "last-commit walk failed");
102 HashMap::new()81 HashMap::new()