From 4ee92d0af78e66e72366cecaeccc94ec6de8cc42 Mon Sep 17 00:00:00 2001 From: Grady Ward Date: Wed, 6 Dec 2023 08:28:06 -0700 Subject: [PATCH] Review Comments --- azure/azblob/azblob.go | 10 ---------- cmd/server/pactasrv/BUILD.bazel | 1 + cmd/server/pactasrv/pactasrv.go | 2 +- cmd/server/pactasrv/parallel.go | 24 ++++++++++++++++++++++++ 4 files changed, 26 insertions(+), 11 deletions(-) create mode 100644 cmd/server/pactasrv/parallel.go diff --git a/azure/azblob/azblob.go b/azure/azblob/azblob.go index 1f97db2..819aa40 100644 --- a/azure/azblob/azblob.go +++ b/azure/azblob/azblob.go @@ -101,16 +101,6 @@ func (c *Client) DeleteBlob(ctx context.Context, uri string) error { return nil } -func (c *Client) DeleteBlobs(ctx context.Context, uris []string) error { - // Implement parallel delete if slow - not prematurely optimizing. - for i, uri := range uris { - if err := c.DeleteBlob(ctx, uri); err != nil { - return fmt.Errorf("deleting blob %d/%d: %w", i, len(uris), err) - } - } - return nil -} - // SignedUploadURL returns a URL that is allowed to upload to the given URI. // See https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/storage/azblob@v1.0.0/sas#example-package-UserDelegationSAS func (c *Client) SignedUploadURL(ctx context.Context, uri string) (string, error) { diff --git a/cmd/server/pactasrv/BUILD.bazel b/cmd/server/pactasrv/BUILD.bazel index bd1a4eb..56adada 100644 --- a/cmd/server/pactasrv/BUILD.bazel +++ b/cmd/server/pactasrv/BUILD.bazel @@ -8,6 +8,7 @@ go_library( "initiative_user_relationship.go", "pacta_version.go", "pactasrv.go", + "parallel.go", "portfolio.go", "upload.go", "user.go", diff --git a/cmd/server/pactasrv/pactasrv.go b/cmd/server/pactasrv/pactasrv.go index ef3850f..fb5d057 100644 --- a/cmd/server/pactasrv/pactasrv.go +++ b/cmd/server/pactasrv/pactasrv.go @@ -87,7 +87,7 @@ type Blob interface { SignedUploadURL(ctx context.Context, uri string) (string, error) // For downloading reports SignedDownloadURL(ctx context.Context, uri string) (string, error) - DeleteBlobs(ctx context.Context, uris []string) error + DeleteBlob(ctx context.Context, uri string) error } type Server struct { diff --git a/cmd/server/pactasrv/parallel.go b/cmd/server/pactasrv/parallel.go new file mode 100644 index 0000000..16938f5 --- /dev/null +++ b/cmd/server/pactasrv/parallel.go @@ -0,0 +1,24 @@ +package pactasrv + +import ( + "context" + "fmt" +) + +type blobDeleter interface { + DeleteBlob(ctx context.Context, uri string) error +} + +func deleteBlobs(ctx context.Context, bd blobDeleter, uris []string) error { + // Implement parallel delete if slow - not prematurely optimizing. + for i, uri := range uris { + if err := bd.DeleteBlob(ctx, uri); err != nil { + return fmt.Errorf("deleting blob %d/%d: %w", i, len(uris), err) + } + } + return nil +} + +func (s *Server) deleteBlobs(ctx context.Context, uris []string) error { + return deleteBlobs(ctx, s.Blob, uris) +}