perf(scanner): Change DataUseageEntry from clone to borrow (#1757)

Signed-off-by: evan slack <51209817+evanofslack@users.noreply.github.com>
Signed-off-by: houseme <housemecn@gmail.com>
Co-authored-by: loverustfs <hello@rustfs.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: houseme <housemecn@gmail.com>
This commit is contained in:
evan slack
2026-02-09 19:53:26 -05:00
committed by GitHub
parent f4e9ef2edc
commit 682b5bbb2f
2 changed files with 12 additions and 18 deletions
+11 -14
View File
@@ -621,8 +621,8 @@ impl DataUsageCache {
} }
} }
pub fn find(&self, path: &str) -> Option<DataUsageEntry> { pub fn find(&self, path: &str) -> Option<&DataUsageEntry> {
self.cache.get(&hash_path(path).key()).cloned() self.cache.get(&hash_path(path).key())
} }
pub fn find_children_copy(&mut self, h: DataUsageHash) -> DataUsageHashMap { pub fn find_children_copy(&mut self, h: DataUsageHash) -> DataUsageHashMap {
@@ -677,10 +677,10 @@ impl DataUsageCache {
match self.find(path) { match self.find(path) {
Some(root) => { Some(root) => {
if root.children.is_empty() { if root.children.is_empty() {
return Some(root); return Some(root.clone());
} }
let mut flat = self.flatten(&root); let mut flat = self.flatten(root);
if flat.replication_stats.is_some() && flat.replication_stats.as_ref().unwrap().empty() { if flat.replication_stats.as_ref().is_some_and(|rs| rs.empty()) {
flat.replication_stats = None; flat.replication_stats = None;
} }
Some(flat) Some(flat)
@@ -721,7 +721,7 @@ impl DataUsageCache {
} }
let top = hash_path(&self.info.name).key(); let top = hash_path(&self.info.name).key();
let top_e = match self.find(&top) { let top_e = match self.find(&top) {
Some(e) => e, Some(e) => e.clone(),
None => return, None => return,
}; };
// Note: DATA_SCANNER_FORCE_COMPACT_AT_FOLDERS constant would need to be passed as parameter // Note: DATA_SCANNER_FORCE_COMPACT_AT_FOLDERS constant would need to be passed as parameter
@@ -797,12 +797,9 @@ impl DataUsageCache {
} }
pub fn total_children_rec(&self, path: &str) -> usize { pub fn total_children_rec(&self, path: &str) -> usize {
let root = self.find(path); let Some(root) = self.find(path) else {
if root.is_none() {
return 0; return 0;
} };
let root = root.unwrap();
if root.children.is_empty() { if root.children.is_empty() {
return 0; return 0;
} }
@@ -848,7 +845,7 @@ impl DataUsageCache {
} }
pub fn root(&self) -> Option<DataUsageEntry> { pub fn root(&self) -> Option<DataUsageEntry> {
self.find(&self.info.name) self.find(&self.info.name).cloned()
} }
/// Convert cache to DataUsageInfo for a specific path /// Convert cache to DataUsageInfo for a specific path
@@ -857,7 +854,7 @@ impl DataUsageCache {
Some(e) => e, Some(e) => e,
None => return DataUsageInfo::default(), None => return DataUsageInfo::default(),
}; };
let flat = self.flatten(&e); let flat = self.flatten(e);
let mut buckets_usage = HashMap::new(); let mut buckets_usage = HashMap::new();
for bucket_name in buckets.iter() { for bucket_name in buckets.iter() {
@@ -865,7 +862,7 @@ impl DataUsageCache {
Some(e) => e, Some(e) => e,
None => continue, None => continue,
}; };
let flat = self.flatten(&e); let flat = self.flatten(e);
let mut bui = BucketUsageInfo { let mut bui = BucketUsageInfo {
size: flat.size as u64, size: flat.size as u64,
versions_count: flat.versions as u64, versions_count: flat.versions as u64,
+1 -4
View File
@@ -734,10 +734,7 @@ impl FolderScanner {
self.send_update().await; self.send_update().await;
} }
if !into.compacted if !into.compacted && self.update_cache.find(&this_hash.key()).is_some_and(|v| !v.compacted) {
&& let Some(parent) = self.update_cache.find(&this_hash.key())
&& !parent.compacted
{
self.update_cache.delete_recursive(&h); self.update_cache.delete_recursive(&h);
self.update_cache self.update_cache
.copy_with_children(&self.new_cache, &h, &Some(this_hash.clone())); .copy_with_children(&self.new_cache, &h, &Some(this_hash.clone()));