mirror of
https://github.com/rustfs/rustfs.git
synced 2026-07-26 16:28:15 +00:00
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:
@@ -621,8 +621,8 @@ impl DataUsageCache {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn find(&self, path: &str) -> Option<DataUsageEntry> {
|
||||
self.cache.get(&hash_path(path).key()).cloned()
|
||||
pub fn find(&self, path: &str) -> Option<&DataUsageEntry> {
|
||||
self.cache.get(&hash_path(path).key())
|
||||
}
|
||||
|
||||
pub fn find_children_copy(&mut self, h: DataUsageHash) -> DataUsageHashMap {
|
||||
@@ -677,10 +677,10 @@ impl DataUsageCache {
|
||||
match self.find(path) {
|
||||
Some(root) => {
|
||||
if root.children.is_empty() {
|
||||
return Some(root);
|
||||
return Some(root.clone());
|
||||
}
|
||||
let mut flat = self.flatten(&root);
|
||||
if flat.replication_stats.is_some() && flat.replication_stats.as_ref().unwrap().empty() {
|
||||
let mut flat = self.flatten(root);
|
||||
if flat.replication_stats.as_ref().is_some_and(|rs| rs.empty()) {
|
||||
flat.replication_stats = None;
|
||||
}
|
||||
Some(flat)
|
||||
@@ -721,7 +721,7 @@ impl DataUsageCache {
|
||||
}
|
||||
let top = hash_path(&self.info.name).key();
|
||||
let top_e = match self.find(&top) {
|
||||
Some(e) => e,
|
||||
Some(e) => e.clone(),
|
||||
None => return,
|
||||
};
|
||||
// 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 {
|
||||
let root = self.find(path);
|
||||
|
||||
if root.is_none() {
|
||||
let Some(root) = self.find(path) else {
|
||||
return 0;
|
||||
}
|
||||
let root = root.unwrap();
|
||||
};
|
||||
if root.children.is_empty() {
|
||||
return 0;
|
||||
}
|
||||
@@ -848,7 +845,7 @@ impl DataUsageCache {
|
||||
}
|
||||
|
||||
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
|
||||
@@ -857,7 +854,7 @@ impl DataUsageCache {
|
||||
Some(e) => e,
|
||||
None => return DataUsageInfo::default(),
|
||||
};
|
||||
let flat = self.flatten(&e);
|
||||
let flat = self.flatten(e);
|
||||
|
||||
let mut buckets_usage = HashMap::new();
|
||||
for bucket_name in buckets.iter() {
|
||||
@@ -865,7 +862,7 @@ impl DataUsageCache {
|
||||
Some(e) => e,
|
||||
None => continue,
|
||||
};
|
||||
let flat = self.flatten(&e);
|
||||
let flat = self.flatten(e);
|
||||
let mut bui = BucketUsageInfo {
|
||||
size: flat.size as u64,
|
||||
versions_count: flat.versions as u64,
|
||||
|
||||
@@ -734,10 +734,7 @@ impl FolderScanner {
|
||||
self.send_update().await;
|
||||
}
|
||||
|
||||
if !into.compacted
|
||||
&& let Some(parent) = self.update_cache.find(&this_hash.key())
|
||||
&& !parent.compacted
|
||||
{
|
||||
if !into.compacted && self.update_cache.find(&this_hash.key()).is_some_and(|v| !v.compacted) {
|
||||
self.update_cache.delete_recursive(&h);
|
||||
self.update_cache
|
||||
.copy_with_children(&self.new_cache, &h, &Some(this_hash.clone()));
|
||||
|
||||
Reference in New Issue
Block a user