Add prev delta to cache
This commit is contained in:
parent
479f114514
commit
9af64f8c13
@ -323,6 +323,23 @@ func (c *Collections) Get(
|
||||
"num_deltas_entries", numDeltas,
|
||||
"delta_reset", delta.Reset)
|
||||
|
||||
numDriveItems := c.NumItems - numPrevItems
|
||||
numPrevItems = c.NumItems
|
||||
|
||||
// Attach an url cache
|
||||
if numDriveItems < urlCacheDriveItemThreshold {
|
||||
logger.Ctx(ictx).Info("adding url cache for drive")
|
||||
|
||||
err = c.addURLCacheToDriveCollections(
|
||||
ictx,
|
||||
driveID,
|
||||
prevDelta,
|
||||
errs)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
}
|
||||
|
||||
// For both cases we don't need to do set difference on folder map if the
|
||||
// delta token was valid because we should see all the changes.
|
||||
if !delta.Reset {
|
||||
@ -379,22 +396,6 @@ func (c *Collections) Get(
|
||||
|
||||
c.CollectionMap[driveID][fldID] = col
|
||||
}
|
||||
|
||||
numDriveItems := c.NumItems - numPrevItems
|
||||
numPrevItems = c.NumItems
|
||||
|
||||
// Only create a drive cache if there are less than 300k items in the drive.
|
||||
if numDriveItems < urlCacheDriveItemThreshold {
|
||||
logger.Ctx(ictx).Info("adding url cache for drive")
|
||||
|
||||
err = c.addURLCacheToDriveCollections(
|
||||
ictx,
|
||||
driveID,
|
||||
errs)
|
||||
if err != nil {
|
||||
return nil, false, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
observe.Message(ctx, fmt.Sprintf("Discovered %d items to backup", c.NumItems))
|
||||
@ -461,11 +462,12 @@ func (c *Collections) Get(
|
||||
// a drive.
|
||||
func (c *Collections) addURLCacheToDriveCollections(
|
||||
ctx context.Context,
|
||||
driveID string,
|
||||
driveID, prevDelta string,
|
||||
errs *fault.Bus,
|
||||
) error {
|
||||
uc, err := newURLCache(
|
||||
driveID,
|
||||
prevDelta,
|
||||
urlCacheRefreshInterval,
|
||||
c.handler.NewItemPager(driveID, "", api.DriveItemSelectDefault()),
|
||||
errs)
|
||||
|
||||
@ -2742,6 +2742,7 @@ func (suite *OneDriveCollectionsUnitSuite) TestAddURLCacheToDriveCollections() {
|
||||
err := c.addURLCacheToDriveCollections(
|
||||
ctx,
|
||||
driveID,
|
||||
"",
|
||||
fault.New(true))
|
||||
require.NoError(t, err, clues.ToCore(err))
|
||||
|
||||
|
||||
@ -37,6 +37,7 @@ var _ getItemPropertyer = &urlCache{}
|
||||
// urlCache caches download URLs for drive items
|
||||
type urlCache struct {
|
||||
driveID string
|
||||
prevDelta string
|
||||
idToProps map[string]itemProps
|
||||
lastRefreshTime time.Time
|
||||
refreshInterval time.Duration
|
||||
@ -53,7 +54,7 @@ type urlCache struct {
|
||||
|
||||
// newURLache creates a new URL cache for the specified drive ID
|
||||
func newURLCache(
|
||||
driveID string,
|
||||
driveID, prevDelta string,
|
||||
refreshInterval time.Duration,
|
||||
itemPager api.DriveItemEnumerator,
|
||||
errs *fault.Bus,
|
||||
@ -70,6 +71,7 @@ func newURLCache(
|
||||
idToProps: make(map[string]itemProps),
|
||||
lastRefreshTime: time.Time{},
|
||||
driveID: driveID,
|
||||
prevDelta: prevDelta,
|
||||
refreshInterval: refreshInterval,
|
||||
itemPager: itemPager,
|
||||
errs: errs,
|
||||
@ -179,6 +181,8 @@ func (uc *urlCache) deltaQuery(
|
||||
ctx context.Context,
|
||||
) error {
|
||||
logger.Ctx(ctx).Debug("starting delta query")
|
||||
// Reset item pager to remove any previous state
|
||||
uc.itemPager.Reset()
|
||||
|
||||
_, _, _, err := collectItems(
|
||||
ctx,
|
||||
@ -187,7 +191,7 @@ func (uc *urlCache) deltaQuery(
|
||||
"",
|
||||
uc.updateCache,
|
||||
map[string]string{},
|
||||
"",
|
||||
uc.prevDelta,
|
||||
uc.errs)
|
||||
if err != nil {
|
||||
return clues.Wrap(err, "delta query")
|
||||
|
||||
@ -112,6 +112,7 @@ func (suite *URLCacheIntegrationSuite) TestURLCacheBasic() {
|
||||
// Create a new URL cache with a long TTL
|
||||
cache, err := newURLCache(
|
||||
suite.driveID,
|
||||
"",
|
||||
1*time.Hour,
|
||||
driveItemPager,
|
||||
fault.New(true))
|
||||
@ -404,6 +405,7 @@ func (suite *URLCacheUnitSuite) TestGetItemProperties() {
|
||||
|
||||
cache, err := newURLCache(
|
||||
driveID,
|
||||
"",
|
||||
1*time.Hour,
|
||||
itemPager,
|
||||
fault.New(true))
|
||||
@ -446,6 +448,7 @@ func (suite *URLCacheUnitSuite) TestNeedsRefresh() {
|
||||
|
||||
cache, err := newURLCache(
|
||||
driveID,
|
||||
"",
|
||||
refreshInterval,
|
||||
&mockItemPager{},
|
||||
fault.New(true))
|
||||
@ -519,6 +522,7 @@ func (suite *URLCacheUnitSuite) TestNewURLCache() {
|
||||
t := suite.T()
|
||||
_, err := newURLCache(
|
||||
test.driveID,
|
||||
"",
|
||||
test.refreshInt,
|
||||
test.itemPager,
|
||||
test.errors)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user