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:
ashmrtn 2022-11-30 08:46:32 -08:00 committed by GitHub
parent 467c3c699c
commit 17a8c87168
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 37 additions and 7 deletions

View File

@ -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"))
}

View File

@ -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"))
}

View File

@ -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"))
}

View File

@ -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")
}

View File

@ -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...)
}

View File

@ -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")