Skip to content

Commit

Permalink
chore: cache relationship
Browse files Browse the repository at this point in the history
  • Loading branch information
Okabe-Rintarou-0 committed Oct 1, 2024
1 parent 7884840 commit 3768dfd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src-tauri/src/app/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ use crate::{
utils::{self, TempFile},
};

use super::{constants::COURSES_CACHE_KEY, App};
use super::{
constants::{COURSES_CACHE_KEY, RELATIONSHIP_CACHE_KEY},
App,
};

const MY_CANVAS_FILES_FOLDER_NAME: &str = "我的Canvas文件";

Expand Down Expand Up @@ -851,8 +854,13 @@ impl App {
}

pub async fn collect_relationship(&self) -> Result<RelationshipTopo> {
let topo = self.cache.get(RELATIONSHIP_CACHE_KEY)?;
if let Some(topo) = topo {
return Ok(topo);
}
let token = self.config.read().await.token.clone();
let topo = self.client.clone().collect_relationship(&token).await?;
self.cache.set(RELATIONSHIP_CACHE_KEY, topo.clone())?;
Ok(topo)
}

Expand Down
1 change: 1 addition & 0 deletions src-tauri/src/app/constants.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub const COURSES_CACHE_KEY: &str = "courses_cache_key";
pub const RELATIONSHIP_CACHE_KEY: &str = "relationship_cache_key";

0 comments on commit 3768dfd

Please sign in to comment.