From 3768dfd71238a19254720f428709c6c37988d93c Mon Sep 17 00:00:00 2001 From: "923048992@qq.com" <923048992@qq.com> Date: Tue, 1 Oct 2024 20:11:09 +0800 Subject: [PATCH] chore: cache relationship --- src-tauri/src/app/basic.rs | 10 +++++++++- src-tauri/src/app/constants.rs | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src-tauri/src/app/basic.rs b/src-tauri/src/app/basic.rs index 3e954bb..caba6bb 100644 --- a/src-tauri/src/app/basic.rs +++ b/src-tauri/src/app/basic.rs @@ -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文件"; @@ -851,8 +854,13 @@ impl App { } pub async fn collect_relationship(&self) -> Result { + 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) } diff --git a/src-tauri/src/app/constants.rs b/src-tauri/src/app/constants.rs index bb33a80..a7fdafd 100644 --- a/src-tauri/src/app/constants.rs +++ b/src-tauri/src/app/constants.rs @@ -1 +1,2 @@ pub const COURSES_CACHE_KEY: &str = "courses_cache_key"; +pub const RELATIONSHIP_CACHE_KEY: &str = "relationship_cache_key";