cache filetree

This commit is contained in:
Mylloon 2024-11-09 18:07:35 +01:00
parent a5240fea57
commit 182b17c47f
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

View file

@ -1,5 +1,6 @@
use std::{cmp::Ordering, path::Path}; use std::{cmp::Ordering, path::Path};
use cached::proc_macro::once;
use regex::Regex; use regex::Regex;
use serde::Serialize; use serde::Serialize;
@ -29,10 +30,19 @@ impl PartialOrd for FileNode {
} }
} }
#[once(time = 120)]
pub fn get_filetree( pub fn get_filetree(
dir_path: &str, dir_path: &str,
exclusion_list: &[String], exclusion_list: &[String],
exclusion_patterns: &[Regex], 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 { ) -> FileNode {
let mut children: Vec<FileNode> = std::fs::read_dir(dir_path) let mut children: Vec<FileNode> = std::fs::read_dir(dir_path)
.unwrap() .unwrap()
@ -54,7 +64,7 @@ pub fn get_filetree(
}) })
} else { } else {
// Exclude empty directories // Exclude empty directories
let children_of_children = get_filetree( let children_of_children = gen_filetree(
entry_path.to_str().unwrap(), entry_path.to_str().unwrap(),
exclusion_list, exclusion_list,
exclusion_patterns, exclusion_patterns,