Added prefetch
This commit is contained in:
@@ -193,14 +193,13 @@ impl FurumiClient {
|
||||
.time_to_live(Duration::from_secs(30))
|
||||
.build();
|
||||
|
||||
let this = Self { client, attr_cache, dir_cache };
|
||||
this.start_background_sync();
|
||||
Ok(this)
|
||||
Ok(Self { client, attr_cache, dir_cache })
|
||||
}
|
||||
|
||||
/// Spawns background tasks that pre-warm the cache with a server snapshot and then
|
||||
/// subscribe to live change events to keep it up to date.
|
||||
fn start_background_sync(&self) {
|
||||
/// Must be called after a successful authentication check.
|
||||
pub fn start_background_sync(&self) {
|
||||
let this = self.clone();
|
||||
tokio::spawn(async move {
|
||||
match this.load_snapshot("/", 3).await {
|
||||
|
||||
@@ -63,7 +63,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
if let Err(e) = c.get_attr("/").await {
|
||||
return Err(format!("Failed to authenticate or connect to server: {}", e).into());
|
||||
}
|
||||
|
||||
|
||||
// Auth verified — start background snapshot + watch sync
|
||||
c.start_background_sync();
|
||||
|
||||
Ok::<_, Box<dyn std::error::Error>>(c)
|
||||
})?;
|
||||
|
||||
|
||||
@@ -58,7 +58,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
format!("https://{}", args.server)
|
||||
};
|
||||
|
||||
let client = rt.block_on(async { FurumiClient::connect(&full_addr, &args.token).await })?;
|
||||
let client = rt.block_on(async {
|
||||
let c = FurumiClient::connect(&full_addr, &args.token).await?;
|
||||
c.start_background_sync();
|
||||
Ok::<_, Box<dyn std::error::Error + Send + Sync>>(c)
|
||||
})?;
|
||||
|
||||
let furumi_nfs = nfs::FurumiNfs::new(client);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user