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?

- [ ]  Yes, it's included
- [ ] 🕐 Yes, but in a later PR
- [x]  No

#### Type of change

- [x] 🌻 Feature
- [ ] 🐛 Bugfix
- [ ] 🗺️ Documentation
- [ ] 🤖 Supportability/Tests
- [ ] 💻 CI/Deployment
- [ ] 🧹 Tech Debt/Cleanup

#### Test Plan

- [x] 💪 Manual
- [ ]  Unit test
- [ ] 💚 E2E
This commit is contained in:
ashmrtn 2023-11-16 12:14:31 -08:00 committed by GitHub
parent 1cbabdb73a
commit 7a21424ca7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -70,6 +70,12 @@ func NewCollections(
} }
} }
func (c *Collections) resetStats() {
c.NumItems = 0
c.NumFiles = 0
c.NumContainers = 0
}
func deserializeAndValidateMetadata( func deserializeAndValidateMetadata(
ctx context.Context, ctx context.Context,
cols []data.RestoreCollection, cols []data.RestoreCollection,
@ -756,6 +762,8 @@ func (c *Collections) PopulateDriveCollections(
seenFolders = map[string]string{} seenFolders = map[string]string{}
c.CollectionMap[driveID] = map[string]*Collection{} c.CollectionMap[driveID] = map[string]*Collection{}
invalidPrevDelta = true invalidPrevDelta = true
c.resetStats()
} }
for _, item := range page { for _, item := range page {
@ -975,8 +983,8 @@ func (c *Collections) processItem(
// This will only kick in if the file was moved multiple times // This will only kick in if the file was moved multiple times
// within a single delta query. We delete the file from the previous // within a single delta query. We delete the file from the previous
// collection so that it doesn't appear in two places. // collection so that it doesn't appear in two places.
prevParentContainerID, ok := currPrevPaths[itemID] prevParentContainerID, alreadyAdded := currPrevPaths[itemID]
if ok { if alreadyAdded {
prevColl, found := c.CollectionMap[driveID][prevParentContainerID] prevColl, found := c.CollectionMap[driveID][prevParentContainerID]
if !found { if !found {
return clues.NewWC(ctx, "previous collection not found"). return clues.NewWC(ctx, "previous collection not found").
@ -991,7 +999,9 @@ func (c *Collections) processItem(
currPrevPaths[itemID] = parentID 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.NumItems++
c.NumFiles++ c.NumFiles++
} }