diff --git a/src/internal/m365/collection/drive/collections.go b/src/internal/m365/collection/drive/collections.go index 6964774b8..b88de4aaa 100644 --- a/src/internal/m365/collection/drive/collections.go +++ b/src/internal/m365/collection/drive/collections.go @@ -471,7 +471,7 @@ func (c *Collections) addURLCacheToDriveCollections( driveID, prevDelta, urlCacheRefreshInterval, - c.handler.NewItemPager(driveID, "", api.DriveItemSelectDefault()), + c.handler.NewItemPager(driveID, "", api.DriveItemSelectURLCache()), errs) if err != nil { return err diff --git a/src/internal/m365/collection/drive/url_cache_test.go b/src/internal/m365/collection/drive/url_cache_test.go index f2fd257b8..68b5b8a8b 100644 --- a/src/internal/m365/collection/drive/url_cache_test.go +++ b/src/internal/m365/collection/drive/url_cache_test.go @@ -3,6 +3,7 @@ package drive import ( "context" "errors" + "io" "math/rand" "net/http" "sync" @@ -87,6 +88,7 @@ func (suite *URLCacheIntegrationSuite) TestURLCacheBasic() { newItem(newFolderName, true), control.Copy) require.NoError(t, err, clues.ToCore(err)) + require.NotNil(t, newFolder.GetId()) nfid := ptr.Val(newFolder.GetId()) @@ -109,7 +111,7 @@ func (suite *URLCacheIntegrationSuite) TestURLCacheBasic() { // Get the previous delta to feed into url cache prevDelta, _, _, err := collectItems( ctx, - suite.ac.Drives().NewDriveItemDeltaPager(driveID, "", api.DriveItemSelectDefault()), + suite.ac.Drives().NewDriveItemDeltaPager(driveID, "", api.DriveItemSelectURLCache()), suite.driveID, "drive-name", collectorFunc, @@ -131,10 +133,7 @@ func (suite *URLCacheIntegrationSuite) TestURLCacheBasic() { nfid, newItem(newItemName, false), control.Copy) - if err != nil { - // Something bad happened, skip this item - continue - } + require.NoError(t, err, clues.ToCore(err)) items = append(items, item) } @@ -176,13 +175,23 @@ func (suite *URLCacheIntegrationSuite) TestURLCacheBasic() { nil, nil) require.NoError(t, err, clues.ToCore(err)) + + require.NotNil(t, resp) + require.NotNil(t, resp.Body) + + defer func(rc io.ReadCloser) { + if rc != nil { + rc.Close() + } + }(resp.Body) + require.Equal(t, http.StatusOK, resp.StatusCode) }(i) } wg.Wait() - // Validate that <= 1 delta queries were made by url cache - require.LessOrEqual(t, uc.deltaQueryCount, 1) + // Validate that exactly 1 delta query was made by url cache + require.Equal(t, 1, uc.deltaQueryCount) } type URLCacheUnitSuite struct { diff --git a/src/pkg/services/m365/api/config.go b/src/pkg/services/m365/api/config.go index 9e2247279..a1c752686 100644 --- a/src/pkg/services/m365/api/config.go +++ b/src/pkg/services/m365/api/config.go @@ -112,3 +112,12 @@ func DriveItemSelectDefault() []string { "malware", "shared") } + +// URL cache only needs a subset of item properties +func DriveItemSelectURLCache() []string { + return idAnd( + "content.downloadUrl", + "deleted", + "file", + "folder") +}