From 182b17c47f6ef3e40a49923de340d8d5ef688deb Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sat, 9 Nov 2024 18:07:35 +0100 Subject: [PATCH] cache filetree --- src/utils/routes/cours.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/utils/routes/cours.rs b/src/utils/routes/cours.rs index 3259bbd..33ce89e 100644 --- a/src/utils/routes/cours.rs +++ b/src/utils/routes/cours.rs @@ -1,5 +1,6 @@ use std::{cmp::Ordering, path::Path}; +use cached::proc_macro::once; use regex::Regex; use serde::Serialize; @@ -29,10 +30,19 @@ impl PartialOrd for FileNode { } } +#[once(time = 120)] pub fn get_filetree( dir_path: &str, exclusion_list: &[String], exclusion_patterns: &[Regex], +) -> FileNode { + gen_filetree(dir_path, exclusion_list, exclusion_patterns) +} + +fn gen_filetree( + dir_path: &str, + exclusion_list: &[String], + exclusion_patterns: &[Regex], ) -> FileNode { let mut children: Vec = std::fs::read_dir(dir_path) .unwrap() @@ -54,7 +64,7 @@ pub fn get_filetree( }) } else { // Exclude empty directories - let children_of_children = get_filetree( + let children_of_children = gen_filetree( entry_path.to_str().unwrap(), exclusion_list, exclusion_patterns,