From 7a21424ca7956c88c48bc151827ea7c1a422a1c8 Mon Sep 17 00:00:00 2001 From: ashmrtn <3891298+ashmrtn@users.noreply.github.com> Date: Thu, 16 Nov 2023 12:14:31 -0800 Subject: [PATCH] Minor cleanup for drive backup code (#4698) Just a few minor updates to stats logic to reset the counters if the delta is reset and also only count items if they weren't previously seen and counted. --- #### Does this PR need a docs update or release note? - [ ] :white_check_mark: Yes, it's included - [ ] :clock1: Yes, but in a later PR - [x] :no_entry: No #### Type of change - [x] :sunflower: Feature - [ ] :bug: Bugfix - [ ] :world_map: Documentation - [ ] :robot: Supportability/Tests - [ ] :computer: CI/Deployment - [ ] :broom: Tech Debt/Cleanup #### Test Plan - [x] :muscle: Manual - [ ] :zap: Unit test - [ ] :green_heart: E2E --- .../m365/collection/drive/collections.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/internal/m365/collection/drive/collections.go b/src/internal/m365/collection/drive/collections.go index 6aacaef1a..a26e01411 100644 --- a/src/internal/m365/collection/drive/collections.go +++ b/src/internal/m365/collection/drive/collections.go @@ -70,6 +70,12 @@ func NewCollections( } } +func (c *Collections) resetStats() { + c.NumItems = 0 + c.NumFiles = 0 + c.NumContainers = 0 +} + func deserializeAndValidateMetadata( ctx context.Context, cols []data.RestoreCollection, @@ -756,6 +762,8 @@ func (c *Collections) PopulateDriveCollections( seenFolders = map[string]string{} c.CollectionMap[driveID] = map[string]*Collection{} invalidPrevDelta = true + + c.resetStats() } for _, item := range page { @@ -975,8 +983,8 @@ func (c *Collections) processItem( // This will only kick in if the file was moved multiple times // within a single delta query. We delete the file from the previous // collection so that it doesn't appear in two places. - prevParentContainerID, ok := currPrevPaths[itemID] - if ok { + prevParentContainerID, alreadyAdded := currPrevPaths[itemID] + if alreadyAdded { prevColl, found := c.CollectionMap[driveID][prevParentContainerID] if !found { return clues.NewWC(ctx, "previous collection not found"). @@ -991,7 +999,9 @@ func (c *Collections) processItem( currPrevPaths[itemID] = parentID - if collection.Add(item) { + // Only increment counters if the file didn't already get counted (i.e. it's + // not an item that was either updated or moved during the delta query). + if collection.Add(item) && !alreadyAdded { c.NumItems++ c.NumFiles++ }