From 45aac829dc67597aecaef3fbdb933b9daf149fe8 Mon Sep 17 00:00:00 2001 From: ryanfkeepers Date: Wed, 11 Oct 2023 10:11:18 -0600 Subject: [PATCH] rename/recount url cache delta queries, update test --- .../m365/collection/drive/url_cache.go | 8 +++---- .../m365/collection/drive/url_cache_test.go | 23 ++++++++++--------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/internal/m365/collection/drive/url_cache.go b/src/internal/m365/collection/drive/url_cache.go index 786afff0d..71ec66793 100644 --- a/src/internal/m365/collection/drive/url_cache.go +++ b/src/internal/m365/collection/drive/url_cache.go @@ -44,8 +44,8 @@ type urlCache struct { // cacheMu protects idToProps and lastRefreshTime cacheMu sync.RWMutex // refreshMu serializes cache refresh attempts by potential writers - refreshMu sync.Mutex - deltaQueryCount int + refreshMu sync.Mutex + refreshCount int enumerator EnumerateDriveItemsDeltaer @@ -154,8 +154,8 @@ func (uc *urlCache) refreshCache( uc.cacheMu.Lock() defer uc.cacheMu.Unlock() - // Issue a delta query to graph logger.Ctx(ctx).Info("refreshing url cache") + uc.refreshCount++ pager := uc.enumerator.EnumerateDriveItemsDelta( ctx, @@ -166,8 +166,6 @@ func (uc *urlCache) refreshCache( }) for page, reset, done := pager.NextPage(); !done; { - uc.deltaQueryCount++ - err := uc.updateCache( ctx, page, diff --git a/src/internal/m365/collection/drive/url_cache_test.go b/src/internal/m365/collection/drive/url_cache_test.go index 72fc1c2cd..ad675fb27 100644 --- a/src/internal/m365/collection/drive/url_cache_test.go +++ b/src/internal/m365/collection/drive/url_cache_test.go @@ -183,7 +183,7 @@ func (suite *URLCacheIntegrationSuite) TestURLCacheBasic() { wg.Wait() // Validate that exactly 1 delta query was made by url cache - require.Equal(t, 1, uc.deltaQueryCount) + require.Equal(t, 1, uc.refreshCount) } // --------------------------------------------------------------------------- @@ -226,7 +226,7 @@ func (suite *URLCacheUnitSuite) TestGetItemProperties() { expectErr: assert.NoError, expect: func(t *testing.T, uc *urlCache, startTime time.Time) { assert.Greater(t, uc.lastRefreshTime, startTime) - assert.Equal(t, 1, uc.deltaQueryCount) + assert.Equal(t, 1, uc.refreshCount) assert.Equal(t, 1, len(uc.idToProps)) }, }, @@ -266,7 +266,7 @@ func (suite *URLCacheUnitSuite) TestGetItemProperties() { expectErr: assert.NoError, expect: func(t *testing.T, uc *urlCache, startTime time.Time) { assert.Greater(t, uc.lastRefreshTime, startTime) - assert.Equal(t, 1, uc.deltaQueryCount) + assert.Equal(t, 1, uc.refreshCount) assert.Equal(t, 5, len(uc.idToProps)) }, }, @@ -308,7 +308,7 @@ func (suite *URLCacheUnitSuite) TestGetItemProperties() { expectErr: assert.NoError, expect: func(t *testing.T, uc *urlCache, startTime time.Time) { assert.Greater(t, uc.lastRefreshTime, startTime) - assert.Equal(t, 2, uc.deltaQueryCount) + assert.Equal(t, 2, uc.refreshCount) assert.Equal(t, 5, len(uc.idToProps)) }, }, @@ -328,6 +328,7 @@ func (suite *URLCacheUnitSuite) TestGetItemProperties() { }, { Items: []models.DriveItemable{ + fileItem("0", "file1", "root", "root", "https://dummy0.com", false), fileItem("1", "file1", "root", "root", "https://dummy1.com", false), fileItem("2", "file2", "root", "root", "https://dummy2.com", false), fileItem("3", "file3", "root", "root", "https://dummy3.com", false), @@ -365,7 +366,7 @@ func (suite *URLCacheUnitSuite) TestGetItemProperties() { expectErr: assert.NoError, expect: func(t *testing.T, uc *urlCache, startTime time.Time) { assert.Greater(t, uc.lastRefreshTime, startTime) - assert.Equal(t, 4, uc.deltaQueryCount) + assert.Equal(t, 4, uc.refreshCount) assert.Equal(t, 5, len(uc.idToProps)) }, }, @@ -419,7 +420,7 @@ func (suite *URLCacheUnitSuite) TestGetItemProperties() { expectErr: assert.NoError, expect: func(t *testing.T, uc *urlCache, startTime time.Time) { assert.Greater(t, uc.lastRefreshTime, startTime) - assert.Equal(t, 3, uc.deltaQueryCount) + assert.Equal(t, 3, uc.refreshCount) assert.Equal(t, 5, len(uc.idToProps)) }, }, @@ -451,7 +452,7 @@ func (suite *URLCacheUnitSuite) TestGetItemProperties() { expectErr: assert.NoError, expect: func(t *testing.T, uc *urlCache, startTime time.Time) { assert.Greater(t, uc.lastRefreshTime, startTime) - assert.Equal(t, 1, uc.deltaQueryCount) + assert.Equal(t, 1, uc.refreshCount) assert.Equal(t, 3, len(uc.idToProps)) }, }, @@ -477,7 +478,7 @@ func (suite *URLCacheUnitSuite) TestGetItemProperties() { expectErr: assert.NoError, expect: func(t *testing.T, uc *urlCache, startTime time.Time) { assert.Greater(t, uc.lastRefreshTime, startTime) - assert.Equal(t, 1, uc.deltaQueryCount) + assert.Equal(t, 1, uc.refreshCount) assert.Equal(t, 2, len(uc.idToProps)) }, }, @@ -494,7 +495,7 @@ func (suite *URLCacheUnitSuite) TestGetItemProperties() { expectErr: assert.Error, expect: func(t *testing.T, uc *urlCache, startTime time.Time) { assert.Greater(t, uc.lastRefreshTime, startTime) - assert.Equal(t, 1, uc.deltaQueryCount) + assert.Equal(t, 1, uc.refreshCount) assert.Equal(t, 1, len(uc.idToProps)) }, }, @@ -511,7 +512,7 @@ func (suite *URLCacheUnitSuite) TestGetItemProperties() { expectErr: assert.Error, expect: func(t *testing.T, uc *urlCache, startTime time.Time) { assert.Equal(t, time.Time{}, uc.lastRefreshTime) - assert.NotZero(t, uc.deltaQueryCount) + assert.NotZero(t, uc.refreshCount) assert.Equal(t, 0, len(uc.idToProps)) }, }, @@ -530,7 +531,7 @@ func (suite *URLCacheUnitSuite) TestGetItemProperties() { expectErr: assert.Error, expect: func(t *testing.T, uc *urlCache, startTime time.Time) { assert.Greater(t, uc.lastRefreshTime, startTime) - assert.Equal(t, 1, uc.deltaQueryCount) + assert.Equal(t, 1, uc.refreshCount) assert.Equal(t, 1, len(uc.idToProps)) }, },