cache filetree
This commit is contained in:
parent
a5240fea57
commit
182b17c47f
1 changed files with 11 additions and 1 deletions
|
@ -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,
|
||||||
|
|
Loading…
Reference in a new issue