[pbs-devel] [PATCH v7 proxmox-backup 01/31] sync: pull: optimize backup group sorting
Christian Ebner
c.ebner at proxmox.com
Mon Nov 11 16:43:23 CET 2024
`BackupGroup` implements `cmp::Ord`, so use that implementation for
comparing groups during sorting. Furtuher, only sort the list of
backup groups after filtering, thereby possibly reducing the number
of required comparisons.
No functional changes.
Signed-off-by: Christian Ebner <c.ebner at proxmox.com>
---
changes since version 6:
- not present in previous version
src/server/pull.rs | 16 +++++-----------
1 file changed, 5 insertions(+), 11 deletions(-)
diff --git a/src/server/pull.rs b/src/server/pull.rs
index d9584776e..c12ecec82 100644
--- a/src/server/pull.rs
+++ b/src/server/pull.rs
@@ -829,22 +829,16 @@ pub(crate) async fn pull_ns(
namespace: &BackupNamespace,
params: &mut PullParameters,
) -> Result<(StoreProgress, SyncStats, bool), Error> {
- let mut list: Vec<BackupGroup> = params.source.list_groups(namespace, ¶ms.owner).await?;
-
- list.sort_unstable_by(|a, b| {
- let type_order = a.ty.cmp(&b.ty);
- if type_order == std::cmp::Ordering::Equal {
- a.id.cmp(&b.id)
- } else {
- type_order
- }
- });
+ let list: Vec<BackupGroup> = params.source.list_groups(namespace, ¶ms.owner).await?;
let unfiltered_count = list.len();
- let list: Vec<BackupGroup> = list
+ let mut list: Vec<BackupGroup> = list
.into_iter()
.filter(|group| group.apply_filters(¶ms.group_filter))
.collect();
+
+ list.sort_unstable();
+
info!(
"found {} groups to sync (out of {unfiltered_count} total)",
list.len()
--
2.39.5
More information about the pbs-devel
mailing list