GC. EventCalendarResolver Populate() refactor (#1518)

## Description
Iterator Removal from Event Resolver.
The iterator overhead contributes to the complexities of the GC backup pipeline. Issue 1486's goal is to remove errors that are populated from non-error scenarios (e.g. container no longer exists).  
- Stage 1: Reduce the number of error clauses in `Populate()` function
- Stage 2: Update the M365ID retrieval process per resolver

PR introduces Iterate approach used in `delta` functionality to populate the event calendar resolver.  Reduces the amount of calls and variable creation during the populate function. The increase in efficiency will reduce the amount of time `concurrent` Mailbox queries are being made (application throttling).
<!-- Insert PR description-->

## Type of change

<!--- Please check the type of change your PR introduces: --->
- [x] 🌻 Feature
- [x] 🐹 Trivial/Minor

## Issue(s)
Related to #1486 

## Test Plan

- [x]  Unit test
This commit is contained in:
Danny 2022-11-16 11:17:59 -05:00 committed by GitHub
parent f938821960
commit 16e9f07d1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,8 +3,7 @@ package exchange
import (
"context"
msgraphgocore "github.com/microsoftgraph/msgraph-sdk-go-core"
"github.com/microsoftgraph/msgraph-sdk-go/models"
mscal "github.com/microsoftgraph/msgraph-sdk-go/users/item/calendars"
"github.com/pkg/errors"
"github.com/alcionai/corso/src/internal/connector/graph"
@ -38,68 +37,55 @@ func (ecc *eventCalendarCache) Populate(
}
var (
asyncError error
directories = make(map[string]graph.Container)
errUpdater = func(s string, e error) {
asyncError = support.WrapAndAppend(s, e, err)
}
errs error
directories = make([]graph.Container, 0)
)
query, err := ecc.gs.Client().UsersById(ecc.userID).Calendars().Get(ctx, options)
builder := ecc.gs.Client().UsersById(ecc.userID).Calendars()
for {
resp, err := builder.Get(ctx, options)
if err != nil {
return errors.Wrap(err, support.ConnectorStackErrorTrace(err))
}
iter, err := msgraphgocore.NewPageIterator(
query,
ecc.gs.Adapter(),
models.CreateCalendarCollectionResponseFromDiscriminatorValue,
)
if err != nil {
return err
}
cb := IterativeCollectCalendarContainers(
directories,
"",
errUpdater,
)
iterateErr := iter.Iterate(ctx, cb)
if iterateErr != nil {
return errors.Wrap(iterateErr, support.ConnectorStackErrorTrace(iterateErr))
}
// check for errors created during iteration
if asyncError != nil {
return err
}
for _, container := range directories {
if err := checkIDAndName(container); err != nil {
iterateErr = support.WrapAndAppend(
for _, cal := range resp.GetValue() {
temp := CreateCalendarDisplayable(cal)
if err := checkIDAndName(temp); err != nil {
errs = support.WrapAndAppend(
"adding folder to cache",
err,
iterateErr,
errs,
)
continue
}
directories = append(directories, temp)
}
if resp.GetOdataNextLink() == nil {
break
}
builder = mscal.NewCalendarsRequestBuilder(*resp.GetOdataNextLink(), ecc.gs.Adapter())
}
for _, container := range directories {
temp := cacheFolder{
Container: container,
p: path.Builder{}.Append(*container.GetDisplayName()),
}
if err := ecc.addFolder(temp); err != nil {
iterateErr = support.WrapAndAppend(
errs = support.WrapAndAppend(
"failure adding "+*container.GetDisplayName(),
err,
iterateErr)
errs)
}
}
return iterateErr
return errs
}
// AddToCache adds container to map in field 'cache'