reduce memuse: fileinfo uses boxed path instead of pathbuf

reduce memuse: fileinfo does not store full metadata
This commit is contained in:
sreedevk
2025-07-13 13:40:41 +00:00
parent 5daec2f531
commit 81e13a14a2
3 changed files with 9 additions and 8 deletions

View File

@@ -2,17 +2,18 @@ use anyhow::Result;
use gxhash::GxHasher; use gxhash::GxHasher;
use memmap2::Mmap; use memmap2::Mmap;
use std::{ use std::{
fs::{self, Metadata}, fs,
hash::Hasher, hash::Hasher,
io::Read, io::Read,
path::PathBuf, path::{Path, PathBuf},
time::SystemTime,
}; };
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct FileInfo { pub struct FileInfo {
pub path: PathBuf, pub path: Box<Path>,
pub size: u64, pub size: u64,
pub filemeta: Metadata, pub modified: SystemTime,
} }
impl FileInfo { impl FileInfo {
@@ -40,9 +41,9 @@ impl FileInfo {
pub fn new(path: PathBuf) -> Result<Self> { pub fn new(path: PathBuf) -> Result<Self> {
let filemeta = std::fs::metadata(&path)?; let filemeta = std::fs::metadata(&path)?;
Ok(Self { Ok(Self {
path, path: path.into_boxed_path(),
filemeta: filemeta.clone(),
size: filemeta.len(), size: filemeta.len(),
modified: filemeta.modified()?,
}) })
} }
} }

View File

@@ -32,7 +32,7 @@ impl Formatter {
} }
pub fn human_mtime(file: &FileInfo) -> Result<String> { pub fn human_mtime(file: &FileInfo) -> Result<String> {
let modified_time: DateTime<Utc> = file.filemeta.modified()?.into(); let modified_time: DateTime<Utc> = file.modified.into();
Ok(modified_time.format("%Y-%m-%d %H:%M:%S").to_string()) Ok(modified_time.format("%Y-%m-%d %H:%M:%S").to_string())
} }

View File

@@ -18,7 +18,7 @@ impl Interactive {
itable.set_titles(row!["index", "filename", "size", "updated_at"]); itable.set_titles(row!["index", "filename", "size", "updated_at"]);
let max_path_size = group let max_path_size = group
.iter() .iter()
.map(|f| f.path.clone().into_os_string().len()) .map(|f| f.path.iter().count())
.max() .max()
.unwrap_or_default(); .unwrap_or_default();