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:
parent
f938821960
commit
16e9f07d1e
@ -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)
|
||||
)
|
||||
|
||||
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))
|
||||
}
|
||||
)
|
||||
|
||||
query, err := ecc.gs.Client().UsersById(ecc.userID).Calendars().Get(ctx, options)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, support.ConnectorStackErrorTrace(err))
|
||||
}
|
||||
for _, cal := range resp.GetValue() {
|
||||
temp := CreateCalendarDisplayable(cal)
|
||||
if err := checkIDAndName(temp); err != nil {
|
||||
errs = support.WrapAndAppend(
|
||||
"adding folder to cache",
|
||||
err,
|
||||
errs,
|
||||
)
|
||||
|
||||
iter, err := msgraphgocore.NewPageIterator(
|
||||
query,
|
||||
ecc.gs.Adapter(),
|
||||
models.CreateCalendarCollectionResponseFromDiscriminatorValue,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
cb := IterativeCollectCalendarContainers(
|
||||
directories,
|
||||
"",
|
||||
errUpdater,
|
||||
)
|
||||
directories = append(directories, temp)
|
||||
}
|
||||
|
||||
iterateErr := iter.Iterate(ctx, cb)
|
||||
if iterateErr != nil {
|
||||
return errors.Wrap(iterateErr, support.ConnectorStackErrorTrace(iterateErr))
|
||||
}
|
||||
if resp.GetOdataNextLink() == nil {
|
||||
break
|
||||
}
|
||||
|
||||
// check for errors created during iteration
|
||||
if asyncError != nil {
|
||||
return err
|
||||
builder = mscal.NewCalendarsRequestBuilder(*resp.GetOdataNextLink(), ecc.gs.Adapter())
|
||||
}
|
||||
|
||||
for _, container := range directories {
|
||||
if err := checkIDAndName(container); err != nil {
|
||||
iterateErr = support.WrapAndAppend(
|
||||
"adding folder to cache",
|
||||
err,
|
||||
iterateErr,
|
||||
)
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
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'
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user