Skip to content

Commit

Permalink
Add new optimize command (#36)
Browse files Browse the repository at this point in the history
* Update baton-sdk

* Add new optimize command that optimizes a c1z on disk.

* don't use fmt.Println

* Use [email protected] instead of the branch
  • Loading branch information
jirwin authored Oct 20, 2023
1 parent 2a20858 commit fbca4c5
Show file tree
Hide file tree
Showing 668 changed files with 155,578 additions and 54,259 deletions.
1 change: 1 addition & 0 deletions cmd/baton/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func main() {
cliCmd.AddCommand(accessCmd())
cliCmd.AddCommand(dumpDBCmd())
cliCmd.AddCommand(syncsCmd())
cliCmd.AddCommand(optimizeDb())

err := cliCmd.ExecuteContext(ctx)
if err != nil {
Expand Down
62 changes: 62 additions & 0 deletions cmd/baton/optimize.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package main

import (
"context"
"fmt"
"os"

"github.com/conductorone/baton-sdk/pkg/dotc1z/manager"
"github.com/conductorone/baton-sdk/pkg/logging"
"github.com/spf13/cobra"
)

func optimizeDb() *cobra.Command {
cmd := &cobra.Command{
Use: "optimize",
Short: "Optimize the c1z file. This may result in a reduction in filesize.",
RunE: runOptimizeDb,
Hidden: true,
}

return cmd
}

func runOptimizeDb(cmd *cobra.Command, args []string) error {
ctx, err := logging.Init(context.Background(), logging.WithLogFormat("console"), logging.WithLogLevel("error"))
if err != nil {
return err
}
c1zPath, err := cmd.Flags().GetString("file")
if err != nil {
return err
}

m, err := manager.New(ctx, c1zPath)
if err != nil {
return err
}
defer m.Close(ctx)

store, err := m.LoadC1Z(ctx)
if err != nil {
return err
}

err = store.Vacuum(ctx)
if err != nil {
return err
}

err = store.Close()
if err != nil {
return err
}

err = m.SaveC1Z(ctx)
if err != nil {
return err
}

_, _ = fmt.Fprintf(os.Stdout, "Optimized C1Z successfully.")
return nil
}
77 changes: 38 additions & 39 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,52 @@ module github.com/conductorone/baton
go 1.20

require (
github.com/conductorone/baton-sdk v0.1.7
github.com/envoyproxy/protoc-gen-validate v1.0.1
github.com/conductorone/baton-sdk v0.1.8
github.com/envoyproxy/protoc-gen-validate v1.0.2
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0
github.com/pterm/pterm v0.12.60
github.com/spf13/cobra v1.7.0
github.com/xuri/excelize/v2 v2.7.1
go.uber.org/zap v1.24.0
google.golang.org/grpc v1.55.0
google.golang.org/protobuf v1.30.0
go.uber.org/zap v1.26.0
google.golang.org/grpc v1.58.3
google.golang.org/protobuf v1.31.0
)

require (
atomicgo.dev/cursor v0.1.1 // indirect
atomicgo.dev/keyboard v0.2.9 // indirect
atomicgo.dev/schedule v0.0.2 // indirect
github.com/aws/aws-sdk-go-v2 v1.18.0 // indirect
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.10 // indirect
github.com/aws/aws-sdk-go-v2/config v1.18.25 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.13.24 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.3 // indirect
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.11.67 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.33 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.27 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.34 // indirect
github.com/aws/aws-sdk-go-v2/internal/v4a v1.0.25 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.11 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.1.28 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.27 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.14.2 // indirect
github.com/aws/aws-sdk-go-v2/service/s3 v1.33.1 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.12.10 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.14.10 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.19.0 // indirect
github.com/aws/smithy-go v1.13.5 // indirect
github.com/aws/aws-sdk-go-v2 v1.21.2 // indirect
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.14 // indirect
github.com/aws/aws-sdk-go-v2/config v1.18.45 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.13.43 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 // indirect
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.11.90 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 // indirect
github.com/aws/aws-sdk-go-v2/internal/v4a v1.1.6 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.15 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.1.38 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.15.6 // indirect
github.com/aws/aws-sdk-go-v2/service/s3 v1.40.2 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 // indirect
github.com/aws/smithy-go v1.15.0 // indirect
github.com/containerd/console v1.0.3 // indirect
github.com/doug-martin/goqu/v9 v9.18.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/glebarez/go-sqlite v1.21.1 // indirect
github.com/glebarez/go-sqlite v1.21.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/google/uuid v1.3.1 // indirect
github.com/gookit/color v1.5.3 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/klauspost/compress v1.16.5 // indirect
github.com/klauspost/compress v1.17.0 // indirect
github.com/lithammer/fuzzysearch v1.1.7 // indirect
github.com/mattn/go-isatty v0.0.18 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
Expand All @@ -60,16 +60,15 @@ require (
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
github.com/xuri/efp v0.0.0-20230422071738-01f4e37c47e9 // indirect
github.com/xuri/nfp v0.0.0-20230503010013-3f38cdbb0b83 // indirect
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.9.0 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/term v0.8.0 // indirect
golang.org/x/text v0.9.0 // indirect
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
modernc.org/libc v1.22.6 // indirect
modernc.org/mathutil v1.5.0 // indirect
modernc.org/memory v1.5.0 // indirect
modernc.org/sqlite v1.22.1 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/term v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231012201019-e917dd12ba7a // indirect
modernc.org/libc v1.24.1 // indirect
modernc.org/mathutil v1.6.0 // indirect
modernc.org/memory v1.7.2 // indirect
modernc.org/sqlite v1.26.0 // indirect
)
Loading

0 comments on commit fbca4c5

Please sign in to comment.