Added prefetch

This commit is contained in:
2026-03-13 18:35:26 +00:00
parent ec4bbd2c8c
commit 28fd5403df
4 changed files with 126 additions and 76 deletions

View File

@@ -233,7 +233,7 @@ impl FurumiClient {
});
}
/// Fetches the server's pre-built directory snapshot and populates `dir_cache`.
/// Fetches the server's pre-built directory snapshot and populates both caches.
/// Returns the number of directories loaded.
async fn load_snapshot(&self, path: &str, depth: u32) -> Result<usize> {
debug!("snapshot: requesting path={} depth={}", path, depth);
@@ -243,18 +243,37 @@ impl FurumiClient {
depth,
});
let mut stream = client.get_snapshot(req).await?.into_inner();
let mut count = 0;
let mut dirs = 0;
let mut attrs_warmed = 0;
while let Some(entry) = stream.next().await {
let entry = entry?;
let n = entry.children.len();
trace!("snapshot: got dir '{}' ({} entries)", entry.path, n);
trace!("snapshot: got dir '{}' ({} entries)", entry.path, entry.children.len());
// Warm attr_cache for the directory itself.
if let Some(dir_attr) = entry.dir_attr {
self.attr_cache.insert(entry.path.clone(), dir_attr).await;
attrs_warmed += 1;
}
// Warm attr_cache for each child (parallel slice: children[i] ↔ child_attrs[i]).
for (child, attr) in entry.children.iter().zip(entry.child_attrs.iter()) {
let child_path = if entry.path == "/" {
format!("/{}", child.name)
} else {
format!("{}/{}", entry.path, child.name)
};
self.attr_cache.insert(child_path, attr.clone()).await;
attrs_warmed += 1;
}
// Populate dir_cache.
self.dir_cache
.insert(entry.path, Arc::new(entry.children))
.await;
count += 1;
dirs += 1;
}
debug!("snapshot: inserted {} dirs into dir_cache", count);
Ok(count)
debug!("snapshot: {} dirs → dir_cache, {} attrs → attr_cache", dirs, attrs_warmed);
Ok(dirs)
}
/// Subscribes to the server's live change events and invalidates `dir_cache` entries.