Add helper function to get category (#4325)
Expand BaseCollection to have a helper function that returns the Category. Attempts to source from the FullPath and falls back to the PreviousPath if necessary. --- #### Does this PR need a docs update or release note? - [ ] ✅ Yes, it's included - [ ] 🕐 Yes, but in a later PR - [x] ⛔ No #### Type of change - [ ] 🌻 Feature - [ ] 🐛 Bugfix - [ ] 🗺️ Documentation - [ ] 🤖 Supportability/Tests - [ ] 💻 CI/Deployment - [x] 🧹 Tech Debt/Cleanup #### Issue(s) * #4319 #### Test Plan - [ ] 💪 Manual - [x] ⚡ Unit test - [ ] 💚 E2E
This commit is contained in:
parent
b2978e15f1
commit
66a1a3a39d
@ -149,6 +149,7 @@ func (suite *CollectionSuite) TestNewBaseCollection() {
|
|||||||
assert.Equal(t, loc, b.LocationPath(), "location path")
|
assert.Equal(t, loc, b.LocationPath(), "location path")
|
||||||
assert.Equal(t, test.expectState, b.State(), "state")
|
assert.Equal(t, test.expectState, b.State(), "state")
|
||||||
assert.Equal(t, test.expectDoNotMerge, b.DoNotMergeItems(), "do not merge")
|
assert.Equal(t, test.expectDoNotMerge, b.DoNotMergeItems(), "do not merge")
|
||||||
|
assert.Equal(t, path.EmailCategory, b.Category(), "category")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -118,6 +118,17 @@ func (col BaseCollection) State() CollectionState {
|
|||||||
return col.state
|
return col.state
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (col BaseCollection) Category() path.CategoryType {
|
||||||
|
switch {
|
||||||
|
case col.FullPath() != nil:
|
||||||
|
return col.FullPath().Category()
|
||||||
|
case col.PreviousPath() != nil:
|
||||||
|
return col.PreviousPath().Category()
|
||||||
|
}
|
||||||
|
|
||||||
|
return path.UnknownCategory
|
||||||
|
}
|
||||||
|
|
||||||
func (col BaseCollection) DoNotMergeItems() bool {
|
func (col BaseCollection) DoNotMergeItems() bool {
|
||||||
return col.doNotMergeItems
|
return col.doNotMergeItems
|
||||||
}
|
}
|
||||||
|
|||||||
@ -186,25 +186,17 @@ func (col *prefetchCollection) streamItems(
|
|||||||
errs *fault.Bus,
|
errs *fault.Bus,
|
||||||
) {
|
) {
|
||||||
var (
|
var (
|
||||||
category path.CategoryType
|
|
||||||
success int64
|
success int64
|
||||||
totalBytes int64
|
totalBytes int64
|
||||||
wg sync.WaitGroup
|
wg sync.WaitGroup
|
||||||
colProgress chan<- struct{}
|
colProgress chan<- struct{}
|
||||||
|
|
||||||
user = col.user
|
user = col.user
|
||||||
|
log = logger.Ctx(ctx).With(
|
||||||
|
"service", path.ExchangeService.String(),
|
||||||
|
"category", col.Category().String())
|
||||||
)
|
)
|
||||||
|
|
||||||
if col.FullPath() != nil {
|
|
||||||
category = col.FullPath().Category()
|
|
||||||
} else {
|
|
||||||
category = col.PreviousPath().Category()
|
|
||||||
}
|
|
||||||
|
|
||||||
log := logger.Ctx(ctx).With(
|
|
||||||
"service", path.ExchangeService.String(),
|
|
||||||
"category", category.String())
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
close(stream)
|
close(stream)
|
||||||
updateStatus(
|
updateStatus(
|
||||||
@ -220,7 +212,7 @@ func (col *prefetchCollection) streamItems(
|
|||||||
if len(col.added)+len(col.removed) > 0 {
|
if len(col.added)+len(col.removed) > 0 {
|
||||||
colProgress = observe.CollectionProgress(
|
colProgress = observe.CollectionProgress(
|
||||||
ctx,
|
ctx,
|
||||||
col.FullPath().Category().HumanString(),
|
col.Category().HumanString(),
|
||||||
col.LocationPath().Elements())
|
col.LocationPath().Elements())
|
||||||
defer close(colProgress)
|
defer close(colProgress)
|
||||||
}
|
}
|
||||||
@ -354,19 +346,12 @@ func (col *lazyFetchCollection) streamItems(
|
|||||||
errs *fault.Bus,
|
errs *fault.Bus,
|
||||||
) {
|
) {
|
||||||
var (
|
var (
|
||||||
category path.CategoryType
|
|
||||||
success int64
|
success int64
|
||||||
colProgress chan<- struct{}
|
colProgress chan<- struct{}
|
||||||
|
|
||||||
user = col.user
|
user = col.user
|
||||||
)
|
)
|
||||||
|
|
||||||
if col.FullPath() != nil {
|
|
||||||
category = col.FullPath().Category()
|
|
||||||
} else {
|
|
||||||
category = col.PreviousPath().Category()
|
|
||||||
}
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
close(stream)
|
close(stream)
|
||||||
updateStatus(
|
updateStatus(
|
||||||
@ -382,7 +367,7 @@ func (col *lazyFetchCollection) streamItems(
|
|||||||
if len(col.added)+len(col.removed) > 0 {
|
if len(col.added)+len(col.removed) > 0 {
|
||||||
colProgress = observe.CollectionProgress(
|
colProgress = observe.CollectionProgress(
|
||||||
ctx,
|
ctx,
|
||||||
col.FullPath().Category().String(),
|
col.Category().HumanString(),
|
||||||
col.LocationPath().Elements())
|
col.LocationPath().Elements())
|
||||||
defer close(colProgress)
|
defer close(colProgress)
|
||||||
}
|
}
|
||||||
@ -415,7 +400,7 @@ func (col *lazyFetchCollection) streamItems(
|
|||||||
"item_id", id,
|
"item_id", id,
|
||||||
"parent_path", path.LoggableDir(parentPath),
|
"parent_path", path.LoggableDir(parentPath),
|
||||||
"service", path.ExchangeService.String(),
|
"service", path.ExchangeService.String(),
|
||||||
"category", category.String())
|
"category", col.Category().String())
|
||||||
|
|
||||||
stream <- &lazyItem{
|
stream <- &lazyItem{
|
||||||
ctx: ictx,
|
ctx: ictx,
|
||||||
|
|||||||
@ -191,7 +191,6 @@ func populateCollections(
|
|||||||
du.Reset),
|
du.Reset),
|
||||||
bh,
|
bh,
|
||||||
qp.ProtectedResource.ID(),
|
qp.ProtectedResource.ID(),
|
||||||
qp.Category,
|
|
||||||
added,
|
added,
|
||||||
removed,
|
removed,
|
||||||
statusUpdater)
|
statusUpdater)
|
||||||
@ -243,7 +242,6 @@ func populateCollections(
|
|||||||
false),
|
false),
|
||||||
bh,
|
bh,
|
||||||
qp.ProtectedResource.ID(),
|
qp.ProtectedResource.ID(),
|
||||||
qp.Category,
|
|
||||||
nil, // no items added
|
nil, // no items added
|
||||||
nil, // this deletes a directory, so no items deleted either
|
nil, // this deletes a directory, so no items deleted either
|
||||||
statusUpdater)
|
statusUpdater)
|
||||||
|
|||||||
@ -18,7 +18,6 @@ import (
|
|||||||
"github.com/alcionai/corso/src/pkg/backup/details"
|
"github.com/alcionai/corso/src/pkg/backup/details"
|
||||||
"github.com/alcionai/corso/src/pkg/fault"
|
"github.com/alcionai/corso/src/pkg/fault"
|
||||||
"github.com/alcionai/corso/src/pkg/logger"
|
"github.com/alcionai/corso/src/pkg/logger"
|
||||||
"github.com/alcionai/corso/src/pkg/path"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -45,7 +44,6 @@ type Collection struct {
|
|||||||
|
|
||||||
getter getChannelMessager
|
getter getChannelMessager
|
||||||
|
|
||||||
category path.CategoryType
|
|
||||||
statusUpdater support.StatusUpdater
|
statusUpdater support.StatusUpdater
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,7 +57,6 @@ func NewCollection(
|
|||||||
baseCol data.BaseCollection,
|
baseCol data.BaseCollection,
|
||||||
getter getChannelMessager,
|
getter getChannelMessager,
|
||||||
protectedResource string,
|
protectedResource string,
|
||||||
category path.CategoryType,
|
|
||||||
added map[string]struct{},
|
added map[string]struct{},
|
||||||
removed map[string]struct{},
|
removed map[string]struct{},
|
||||||
statusUpdater support.StatusUpdater,
|
statusUpdater support.StatusUpdater,
|
||||||
@ -67,7 +64,6 @@ func NewCollection(
|
|||||||
collection := Collection{
|
collection := Collection{
|
||||||
BaseCollection: baseCol,
|
BaseCollection: baseCol,
|
||||||
added: added,
|
added: added,
|
||||||
category: category,
|
|
||||||
getter: getter,
|
getter: getter,
|
||||||
removed: removed,
|
removed: removed,
|
||||||
statusUpdater: statusUpdater,
|
statusUpdater: statusUpdater,
|
||||||
@ -149,7 +145,7 @@ func (col *Collection) streamItems(ctx context.Context, errs *fault.Bus) {
|
|||||||
el = errs.Local()
|
el = errs.Local()
|
||||||
)
|
)
|
||||||
|
|
||||||
ctx = clues.Add(ctx, "category", col.category.String())
|
ctx = clues.Add(ctx, "category", col.Category().String())
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
col.finishPopulation(ctx, streamedItems, totalBytes, errs.Failure())
|
col.finishPopulation(ctx, streamedItems, totalBytes, errs.Failure())
|
||||||
@ -158,7 +154,7 @@ func (col *Collection) streamItems(ctx context.Context, errs *fault.Bus) {
|
|||||||
if len(col.added)+len(col.removed) > 0 {
|
if len(col.added)+len(col.removed) > 0 {
|
||||||
colProgress = observe.CollectionProgress(
|
colProgress = observe.CollectionProgress(
|
||||||
ctx,
|
ctx,
|
||||||
col.FullPath().Category().HumanString(),
|
col.Category().HumanString(),
|
||||||
col.LocationPath().Elements())
|
col.LocationPath().Elements())
|
||||||
defer close(colProgress)
|
defer close(colProgress)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -108,7 +108,6 @@ func (suite *CollectionUnitSuite) TestNewCollection_state() {
|
|||||||
false),
|
false),
|
||||||
nil,
|
nil,
|
||||||
"g",
|
"g",
|
||||||
0,
|
|
||||||
nil, nil,
|
nil, nil,
|
||||||
nil)
|
nil)
|
||||||
assert.Equal(t, test.expect, c.State(), "collection state")
|
assert.Equal(t, test.expect, c.State(), "collection state")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user