Combine collection structs (#3375)
They both implement the same underlying functionality, just in slightly different ways. Combine them so there's less code duplication. --- #### 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 #### Test Plan - [ ] 💪 Manual - [x] ⚡ Unit test - [ ] 💚 E2E
This commit is contained in:
parent
e7d2aeac5d
commit
3be3b72d0a
@ -11,14 +11,19 @@ import (
|
|||||||
"github.com/alcionai/corso/src/pkg/path"
|
"github.com/alcionai/corso/src/pkg/path"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ data.BackupCollection = emptyCollection{}
|
var _ data.BackupCollection = prefixCollection{}
|
||||||
|
|
||||||
type emptyCollection struct {
|
// TODO: move this out of graph. /data would be a much better owner
|
||||||
p path.Path
|
// for a generic struct like this. However, support.StatusUpdater makes
|
||||||
su support.StatusUpdater
|
// it difficult to extract from this package in a generic way.
|
||||||
|
type prefixCollection struct {
|
||||||
|
full path.Path
|
||||||
|
prev path.Path
|
||||||
|
su support.StatusUpdater
|
||||||
|
state data.CollectionState
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c emptyCollection) Items(ctx context.Context, _ *fault.Bus) <-chan data.Stream {
|
func (c prefixCollection) Items(ctx context.Context, _ *fault.Bus) <-chan data.Stream {
|
||||||
res := make(chan data.Stream)
|
res := make(chan data.Stream)
|
||||||
close(res)
|
close(res)
|
||||||
|
|
||||||
@ -28,21 +33,19 @@ func (c emptyCollection) Items(ctx context.Context, _ *fault.Bus) <-chan data.St
|
|||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c emptyCollection) FullPath() path.Path {
|
func (c prefixCollection) FullPath() path.Path {
|
||||||
return c.p
|
return c.full
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c emptyCollection) PreviousPath() path.Path {
|
func (c prefixCollection) PreviousPath() path.Path {
|
||||||
return c.p
|
return c.prev
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c emptyCollection) State() data.CollectionState {
|
func (c prefixCollection) State() data.CollectionState {
|
||||||
// This assumes we won't change the prefix path. Could probably use MovedState
|
return c.state
|
||||||
// as well if we do need to change things around.
|
|
||||||
return data.NotMovedState
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c emptyCollection) DoNotMergeItems() bool {
|
func (c prefixCollection) DoNotMergeItems() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,7 +79,7 @@ func BaseCollections(
|
|||||||
for cat := range categories {
|
for cat := range categories {
|
||||||
ictx := clues.Add(ctx, "base_service", service, "base_category", cat)
|
ictx := clues.Add(ctx, "base_service", service, "base_category", cat)
|
||||||
|
|
||||||
p, err := path.ServicePrefix(tenant, rOwner, service, cat)
|
full, err := path.ServicePrefix(tenant, rOwner, service, cat)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Shouldn't happen.
|
// Shouldn't happen.
|
||||||
err = clues.Wrap(err, "making path").WithClues(ictx)
|
err = clues.Wrap(err, "making path").WithClues(ictx)
|
||||||
@ -87,8 +90,13 @@ func BaseCollections(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// only add this collection if it doesn't already exist in the set.
|
// only add this collection if it doesn't already exist in the set.
|
||||||
if _, ok := collKeys[p.String()]; !ok {
|
if _, ok := collKeys[full.String()]; !ok {
|
||||||
res = append(res, emptyCollection{p: p, su: su})
|
res = append(res, &prefixCollection{
|
||||||
|
prev: full,
|
||||||
|
full: full,
|
||||||
|
su: su,
|
||||||
|
state: data.StateOf(full, full),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,45 +107,11 @@ func BaseCollections(
|
|||||||
// prefix migration
|
// prefix migration
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
var _ data.BackupCollection = prefixCollection{}
|
|
||||||
|
|
||||||
// TODO: move this out of graph. /data would be a much better owner
|
|
||||||
// for a generic struct like this. However, support.StatusUpdater makes
|
|
||||||
// it difficult to extract from this package in a generic way.
|
|
||||||
type prefixCollection struct {
|
|
||||||
full, prev path.Path
|
|
||||||
su support.StatusUpdater
|
|
||||||
state data.CollectionState
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c prefixCollection) Items(ctx context.Context, _ *fault.Bus) <-chan data.Stream {
|
|
||||||
res := make(chan data.Stream)
|
|
||||||
close(res)
|
|
||||||
|
|
||||||
s := support.CreateStatus(ctx, support.Backup, 0, support.CollectionMetrics{}, "")
|
|
||||||
c.su(s)
|
|
||||||
|
|
||||||
return res
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c prefixCollection) FullPath() path.Path {
|
|
||||||
return c.full
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c prefixCollection) PreviousPath() path.Path {
|
|
||||||
return c.prev
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c prefixCollection) State() data.CollectionState {
|
|
||||||
return c.state
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c prefixCollection) DoNotMergeItems() bool {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// Creates a new collection that only handles prefix pathing.
|
// Creates a new collection that only handles prefix pathing.
|
||||||
func NewPrefixCollection(prev, full path.Path, su support.StatusUpdater) (*prefixCollection, error) {
|
func NewPrefixCollection(
|
||||||
|
prev, full path.Path,
|
||||||
|
su support.StatusUpdater,
|
||||||
|
) (*prefixCollection, error) {
|
||||||
if prev != nil {
|
if prev != nil {
|
||||||
if len(prev.Item()) > 0 {
|
if len(prev.Item()) > 0 {
|
||||||
return nil, clues.New("prefix collection previous path contains an item")
|
return nil, clues.New("prefix collection previous path contains an item")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user