GC: Reduce the amount of folders upon restore (#637)

* Issue #595: All collections with the same `fullPath` name are to be stored within the same folder.
This commit is contained in:
Danny 2022-08-23 16:46:59 -04:00 committed by GitHub
parent 6e7335cc4d
commit 3b9c8e284c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 13 deletions

View File

@ -250,16 +250,18 @@ func (gc *GraphConnector) RestoreMessages(ctx context.Context, dcs []data.Collec
policy := control.Copy // TODO policy to be updated from external source after completion of refactoring policy := control.Copy // TODO policy to be updated from external source after completion of refactoring
for _, dc := range dcs { for _, dc := range dcs {
directory := strings.Join(dc.FullPath(), "")
user := dc.FullPath()[1] user := dc.FullPath()[1]
items := dc.Items() items := dc.Items()
pathCounter[strings.Join(dc.FullPath(), "")] = true if _, ok := pathCounter[directory]; !ok {
if policy == control.Copy { pathCounter[directory] = true
folderID, errs = exchange.GetCopyRestoreFolder(&gc.graphService, user) if policy == control.Copy {
if errs != nil { folderID, errs = exchange.GetCopyRestoreFolder(&gc.graphService, user)
return errs if errs != nil {
return errs
}
} }
} }
var exit bool var exit bool
for !exit { for !exit {
select { select {

View File

@ -224,15 +224,28 @@ func (suite *GraphConnectorIntegrationSuite) TestEventsSerializationRegression()
} }
// TestRestoreMessages uses mock data to ensure GraphConnector // TestRestoreMessages uses mock data to ensure GraphConnector
// is able to restore a single messageable item to a Mailbox. // is able to restore a several messageable item to a Mailbox.
// The result should be all successful items restored within the same folder.
func (suite *GraphConnectorIntegrationSuite) TestRestoreMessages() { func (suite *GraphConnectorIntegrationSuite) TestRestoreMessages() {
user := tester.M365UserID(suite.T()) t := suite.T()
connector := loadConnector(t)
user := tester.M365UserID(t)
if len(user) == 0 { if len(user) == 0 {
suite.T().Skip("Environment not configured: missing m365 test user") suite.T().Skip("Environment not configured: missing m365 test user")
} }
mdc := mockconnector.NewMockExchangeCollection([]string{"tenant", user, mailCategory, "Inbox"}, 1)
err := suite.connector.RestoreMessages(context.Background(), []data.Collection{mdc}) collection := make([]data.Collection, 0)
for i := 0; i < 3; i++ {
mdc := mockconnector.NewMockExchangeCollection([]string{"tenant", user, mailCategory, "Inbox"}, 1)
collection = append(collection, mdc)
}
err := connector.RestoreMessages(context.Background(), collection)
assert.NoError(suite.T(), err) assert.NoError(suite.T(), err)
status := connector.AwaitStatus()
assert.NotNil(t, status)
assert.Equal(t, status.ObjectCount, status.Successful)
assert.Equal(t, status.FolderCount, 1)
} }
// TestGraphConnector_SingleMailFolderCollectionQuery verifies single folder support // TestGraphConnector_SingleMailFolderCollectionQuery verifies single folder support

View File

@ -10,7 +10,7 @@ import (
type ConnectorOperationStatus struct { type ConnectorOperationStatus struct {
lastOperation Operation lastOperation Operation
ObjectCount int ObjectCount int
folderCount int FolderCount int
Successful int Successful int
errorCount int errorCount int
incomplete bool incomplete bool
@ -42,7 +42,7 @@ func CreateStatus(
status := ConnectorOperationStatus{ status := ConnectorOperationStatus{
lastOperation: op, lastOperation: op,
ObjectCount: objects, ObjectCount: objects,
folderCount: folders, FolderCount: folders,
Successful: success, Successful: success,
errorCount: numErr, errorCount: numErr,
incomplete: hasErrors, incomplete: hasErrors,
@ -60,7 +60,7 @@ func CreateStatus(
func (cos *ConnectorOperationStatus) String() string { func (cos *ConnectorOperationStatus) String() string {
message := fmt.Sprintf("Action: %s performed on %d of %d objects within %d directories.", cos.lastOperation.String(), message := fmt.Sprintf("Action: %s performed on %d of %d objects within %d directories.", cos.lastOperation.String(),
cos.Successful, cos.ObjectCount, cos.folderCount) cos.Successful, cos.ObjectCount, cos.FolderCount)
if cos.incomplete { if cos.incomplete {
message += " " + cos.incompleteReason message += " " + cos.incompleteReason
} }