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:
ashmrtn 2023-09-21 09:47:48 -07:00 committed by GitHub
parent b2978e15f1
commit 66a1a3a39d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 20 additions and 30 deletions

View File

@ -149,6 +149,7 @@ func (suite *CollectionSuite) TestNewBaseCollection() {
assert.Equal(t, loc, b.LocationPath(), "location path")
assert.Equal(t, test.expectState, b.State(), "state")
assert.Equal(t, test.expectDoNotMerge, b.DoNotMergeItems(), "do not merge")
assert.Equal(t, path.EmailCategory, b.Category(), "category")
})
}
}

View File

@ -118,6 +118,17 @@ func (col BaseCollection) State() CollectionState {
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 {
return col.doNotMergeItems
}

View File

@ -186,24 +186,16 @@ func (col *prefetchCollection) streamItems(
errs *fault.Bus,
) {
var (
category path.CategoryType
success int64
totalBytes int64
wg sync.WaitGroup
colProgress chan<- struct{}
user = col.user
)
if col.FullPath() != nil {
category = col.FullPath().Category()
} else {
category = col.PreviousPath().Category()
}
log := logger.Ctx(ctx).With(
log = logger.Ctx(ctx).With(
"service", path.ExchangeService.String(),
"category", category.String())
"category", col.Category().String())
)
defer func() {
close(stream)
@ -220,7 +212,7 @@ func (col *prefetchCollection) streamItems(
if len(col.added)+len(col.removed) > 0 {
colProgress = observe.CollectionProgress(
ctx,
col.FullPath().Category().HumanString(),
col.Category().HumanString(),
col.LocationPath().Elements())
defer close(colProgress)
}
@ -354,19 +346,12 @@ func (col *lazyFetchCollection) streamItems(
errs *fault.Bus,
) {
var (
category path.CategoryType
success int64
colProgress chan<- struct{}
user = col.user
)
if col.FullPath() != nil {
category = col.FullPath().Category()
} else {
category = col.PreviousPath().Category()
}
defer func() {
close(stream)
updateStatus(
@ -382,7 +367,7 @@ func (col *lazyFetchCollection) streamItems(
if len(col.added)+len(col.removed) > 0 {
colProgress = observe.CollectionProgress(
ctx,
col.FullPath().Category().String(),
col.Category().HumanString(),
col.LocationPath().Elements())
defer close(colProgress)
}
@ -415,7 +400,7 @@ func (col *lazyFetchCollection) streamItems(
"item_id", id,
"parent_path", path.LoggableDir(parentPath),
"service", path.ExchangeService.String(),
"category", category.String())
"category", col.Category().String())
stream <- &lazyItem{
ctx: ictx,

View File

@ -191,7 +191,6 @@ func populateCollections(
du.Reset),
bh,
qp.ProtectedResource.ID(),
qp.Category,
added,
removed,
statusUpdater)
@ -243,7 +242,6 @@ func populateCollections(
false),
bh,
qp.ProtectedResource.ID(),
qp.Category,
nil, // no items added
nil, // this deletes a directory, so no items deleted either
statusUpdater)

View File

@ -18,7 +18,6 @@ import (
"github.com/alcionai/corso/src/pkg/backup/details"
"github.com/alcionai/corso/src/pkg/fault"
"github.com/alcionai/corso/src/pkg/logger"
"github.com/alcionai/corso/src/pkg/path"
)
var (
@ -45,7 +44,6 @@ type Collection struct {
getter getChannelMessager
category path.CategoryType
statusUpdater support.StatusUpdater
}
@ -59,7 +57,6 @@ func NewCollection(
baseCol data.BaseCollection,
getter getChannelMessager,
protectedResource string,
category path.CategoryType,
added map[string]struct{},
removed map[string]struct{},
statusUpdater support.StatusUpdater,
@ -67,7 +64,6 @@ func NewCollection(
collection := Collection{
BaseCollection: baseCol,
added: added,
category: category,
getter: getter,
removed: removed,
statusUpdater: statusUpdater,
@ -149,7 +145,7 @@ func (col *Collection) streamItems(ctx context.Context, errs *fault.Bus) {
el = errs.Local()
)
ctx = clues.Add(ctx, "category", col.category.String())
ctx = clues.Add(ctx, "category", col.Category().String())
defer func() {
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 {
colProgress = observe.CollectionProgress(
ctx,
col.FullPath().Category().HumanString(),
col.Category().HumanString(),
col.LocationPath().Elements())
defer close(colProgress)
}

View File

@ -108,7 +108,6 @@ func (suite *CollectionUnitSuite) TestNewCollection_state() {
false),
nil,
"g",
0,
nil, nil,
nil)
assert.Equal(t, test.expect, c.State(), "collection state")