diff --git a/src/internal/m365/onedrive/collections.go b/src/internal/m365/onedrive/collections.go index a9fa61d1f..08ad3a346 100644 --- a/src/internal/m365/onedrive/collections.go +++ b/src/internal/m365/onedrive/collections.go @@ -388,7 +388,11 @@ func (c *Collections) Get( if numDriveItems < urlCacheDriveItemThreshold { logger.Ctx(ictx).Info("adding url cache for drive ", driveID) - err = c.addURLCacheToDriveCollections(ictx, driveID, errs) + err = c.addURLCacheToDriveCollections( + ictx, + driveID, + c.handler.ItemPager(driveID, "", api.DriveItemSelectDefault()), + errs) if err != nil { return nil, err } @@ -458,13 +462,14 @@ func (c *Collections) Get( func (c *Collections) addURLCacheToDriveCollections( ctx context.Context, driveID string, + pager api.DriveItemEnumerator, errs *fault.Bus, ) error { uc, err := newURLCache( driveID, urlCacheRefreshInterval, errs, - c.handler.ItemPager(driveID, "", api.DriveItemSelectDefault())) + pager) if err != nil { return err } diff --git a/src/internal/m365/onedrive/collections_test.go b/src/internal/m365/onedrive/collections_test.go index bc64875f4..6d1163c8c 100644 --- a/src/internal/m365/onedrive/collections_test.go +++ b/src/internal/m365/onedrive/collections_test.go @@ -2,6 +2,7 @@ package onedrive import ( "context" + "strconv" "testing" "github.com/alcionai/clues" @@ -2678,3 +2679,82 @@ func (suite *OneDriveCollectionsUnitSuite) TestCollectItems() { }) } } + +func (suite *OneDriveCollectionsUnitSuite) TestURLCacheIntegration() { + driveID := "test-drive" + collCount := 3 + + table := []struct { + name string + items []deltaPagerResult + deltaURL string + prevDeltaSuccess bool + prevDelta string + err error + }{ + + { + name: "cache is attached", + }, + } + for _, test := range table { + suite.Run(test.name, func() { + t := suite.T() + + ctx, flush := tester.NewContext() + defer flush() + + c := NewCollections( + &itemBackupHandler{api.Drives{}}, + "test-tenant", + "test-user", + testFolderMatcher{(&selectors.OneDriveBackup{}).Folders(selectors.Any())[0]}, + nil, + control.Options{ToggleFeatures: control.Toggles{}}) + + if _, ok := c.CollectionMap[driveID]; !ok { + c.CollectionMap[driveID] = map[string]*Collection{} + } + + // Add a few collections + for i := 0; i < collCount; i++ { + coll, err := NewCollection( + &itemBackupHandler{api.Drives{}}, + nil, + nil, + driveID, + nil, + control.Options{ToggleFeatures: control.Toggles{}}, + CollectionScopeFolder, + true, + nil) + require.NoError(t, err, clues.ToCore(err)) + + c.CollectionMap[driveID][strconv.Itoa(i)] = coll + require.Equal(t, nil, coll.cache, "cache not nil") + } + + err := c.addURLCacheToDriveCollections( + ctx, + driveID, + &mockItemPager{}, + fault.New(true)) + + require.NoError(t, err, clues.ToCore(err)) + + // Check that all collections have the same cache instance attached + // to them + var uc *urlCache + for _, driveColls := range c.CollectionMap { + for _, coll := range driveColls { + require.NotNil(t, coll.cache, "cache is nil") + if uc == nil { + uc = coll.cache.(*urlCache) + } else { + require.Equal(t, uc, coll.cache, "cache not equal") + } + } + } + }) + } +}