Helper to fetch backups by ID (#1635)
## Description Helper function to fetch backup models by ID. Also renames `Backups` to `BackupsByTag` ## Type of change - [x] 🌻 Feature - [ ] 🐛 Bugfix - [ ] 🗺️ Documentation - [ ] 🤖 Test - [ ] 💻 CI/Deployment - [ ] 🐹 Trivial/Minor ## Issue(s) * #1505 separated from * #1609 ## Test Plan <!-- How will this be tested prior to merging.--> - [ ] 💪 Manual - [x] ⚡ Unit test - [ ] 💚 E2E
This commit is contained in:
parent
467c3c699c
commit
17a8c87168
@ -373,7 +373,7 @@ func listExchangeCmd(cmd *cobra.Command, args []string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
bs, err := r.Backups(ctx, store.Service(path.ExchangeService))
|
||||
bs, err := r.BackupsByTag(ctx, store.Service(path.ExchangeService))
|
||||
if err != nil {
|
||||
return Only(ctx, errors.Wrap(err, "Failed to list backups in the repository"))
|
||||
}
|
||||
|
||||
@ -272,7 +272,7 @@ func listOneDriveCmd(cmd *cobra.Command, args []string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
bs, err := r.Backups(ctx, store.Service(path.OneDriveService))
|
||||
bs, err := r.BackupsByTag(ctx, store.Service(path.OneDriveService))
|
||||
if err != nil {
|
||||
return Only(ctx, errors.Wrap(err, "Failed to list backups in the repository"))
|
||||
}
|
||||
|
||||
@ -261,7 +261,7 @@ func listSharePointCmd(cmd *cobra.Command, args []string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
bs, err := r.Backups(ctx, store.Service(path.SharePointService))
|
||||
bs, err := r.BackupsByTag(ctx, store.Service(path.SharePointService))
|
||||
if err != nil {
|
||||
return Only(ctx, errors.Wrap(err, "Failed to list backups in the repository"))
|
||||
}
|
||||
|
||||
9
src/cli/utils/testdata/opts.go
vendored
9
src/cli/utils/testdata/opts.go
vendored
@ -496,7 +496,14 @@ func (MockBackupGetter) Backup(
|
||||
return nil, errors.New("unexpected call to mock")
|
||||
}
|
||||
|
||||
func (MockBackupGetter) Backups(context.Context, ...store.FilterOption) ([]*backup.Backup, error) {
|
||||
func (MockBackupGetter) Backups(context.Context, []model.StableID) ([]*backup.Backup, error) {
|
||||
return nil, errors.New("unexpected call to mock")
|
||||
}
|
||||
|
||||
func (MockBackupGetter) BackupsByTag(
|
||||
context.Context,
|
||||
...store.FilterOption,
|
||||
) ([]*backup.Backup, error) {
|
||||
return nil, errors.New("unexpected call to mock")
|
||||
}
|
||||
|
||||
|
||||
@ -6,6 +6,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/hashicorp/go-multierror"
|
||||
|
||||
"github.com/alcionai/corso/src/internal/events"
|
||||
"github.com/alcionai/corso/src/internal/kopia"
|
||||
@ -28,7 +29,8 @@ var ErrorRepoAlreadyExists = errors.New("a repository was already initialized wi
|
||||
// repository.
|
||||
type BackupGetter interface {
|
||||
Backup(ctx context.Context, id model.StableID) (*backup.Backup, error)
|
||||
Backups(ctx context.Context, fs ...store.FilterOption) ([]*backup.Backup, error)
|
||||
Backups(ctx context.Context, ids []model.StableID) ([]*backup.Backup, error)
|
||||
BackupsByTag(ctx context.Context, fs ...store.FilterOption) ([]*backup.Backup, error)
|
||||
BackupDetails(
|
||||
ctx context.Context,
|
||||
backupID string,
|
||||
@ -238,8 +240,29 @@ func (r repository) Backup(ctx context.Context, id model.StableID) (*backup.Back
|
||||
return sw.GetBackup(ctx, id)
|
||||
}
|
||||
|
||||
// BackupsByID lists backups by ID. Returns as many backups as possible with
|
||||
// errors for the backups it was unable to retrieve.
|
||||
func (r repository) Backups(ctx context.Context, ids []model.StableID) ([]*backup.Backup, error) {
|
||||
var (
|
||||
errs *multierror.Error
|
||||
bups []*backup.Backup
|
||||
sw = store.NewKopiaStore(r.modelStore)
|
||||
)
|
||||
|
||||
for _, id := range ids {
|
||||
b, err := sw.GetBackup(ctx, id)
|
||||
if err != nil {
|
||||
errs = multierror.Append(errs, err)
|
||||
}
|
||||
|
||||
bups = append(bups, b)
|
||||
}
|
||||
|
||||
return bups, errs.ErrorOrNil()
|
||||
}
|
||||
|
||||
// backups lists backups in a repository
|
||||
func (r repository) Backups(ctx context.Context, fs ...store.FilterOption) ([]*backup.Backup, error) {
|
||||
func (r repository) BackupsByTag(ctx context.Context, fs ...store.FilterOption) ([]*backup.Backup, error) {
|
||||
sw := store.NewKopiaStore(r.modelStore)
|
||||
return sw.GetBackups(ctx, fs...)
|
||||
}
|
||||
|
||||
@ -181,7 +181,7 @@ func runBackupListLoadTest(
|
||||
)
|
||||
|
||||
pprof.Do(ctx, labels, func(ctx context.Context) {
|
||||
bs, err = r.Backups(ctx)
|
||||
bs, err = r.BackupsByTag(ctx)
|
||||
})
|
||||
|
||||
require.NoError(t, err, "retrieving backups")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user