refactor(cache): redesign cache system with structured keys and improved performance

- Add repo_path parameter to cached_response and cached_vec_response functions
- Implement structured cache key format with namespace, repo_path, and request proto
- Replace global cache with Moka in-memory cache using weight-based eviction
- Set 256MB memory cap with 10-minute TTL and 2-minute TTI policy
- Add metrics collection for cache operations and evictions
- Implement efficient repo-scoped invalidation using key structure
- Add detailed documentation comments explaining cache architecture
- Remove outdated dependencies and update dependency versions
- Add error handling for encoding failures in cache operations
- Optimize Vec responses with length-delimited encoding and pre-allocation
This commit is contained in:
zhenyi
2026-06-12 12:53:23 +08:00
parent a40da90ef9
commit 934858bebf
82 changed files with 1273 additions and 4969 deletions
+9 -4
View File
@@ -7,7 +7,7 @@ impl GitBare {
pub fn list_commits(&self, request: ListCommitsRequest) -> GitResult<ListCommitsResponse> {
let revision = resolve_revision!(request.revision.clone());
let base_args = build_rev_list_args(self, &request, &revision);
let base_args = build_rev_list_args(self, &request, &revision)?;
// 1. Get total count via rev-list --count (lightweight, no object parsing)
let total = {
@@ -87,7 +87,7 @@ impl GitBare {
commits
};
let end = start_offset + page_ids.len();
let end = start_offset.saturating_add(page_ids.len());
let has_next = end < total;
let page_info = crate::pb::PageInfo {
next_page_token: if has_next {
@@ -106,7 +106,11 @@ impl GitBare {
}
}
fn build_rev_list_args(gb: &GitBare, request: &ListCommitsRequest, revision: &str) -> Vec<String> {
fn build_rev_list_args(
gb: &GitBare,
request: &ListCommitsRequest,
revision: &str,
) -> GitResult<Vec<String>> {
let mut args = vec![
"--git-dir".to_string(),
gb.bare_dir.to_string_lossy().into_owned(),
@@ -136,10 +140,11 @@ fn build_rev_list_args(gb: &GitBare, request: &ListCommitsRequest, revision: &st
args.push(revision.to_string());
}
if !request.path.is_empty() {
crate::sanitize::validate_file_path(&request.path)?;
args.push("--".into());
args.push(request.path.clone());
}
args
Ok(args)
}
/// Read a single commit from an already-opened gix repo (no subprocess).