Skip to content

Commit

Permalink
Minor refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
cuducos committed Apr 13, 2024
1 parent 4ce81f9 commit 4689efb
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
1 change: 0 additions & 1 deletion download/mirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (

const mirrorURL = "https://mirror.minhareceita.org"

// TODO: do we need to export these structs?
type MirrorFile struct {
URL string `json:"url"`
Size uint `json:"size"`
Expand Down
6 changes: 3 additions & 3 deletions transform/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ func newBadgerStorage(m bool) (*badgerStorage, error) {
var dir string
var err error
var opt badger.Options
if !m {
if m {
opt = badger.DefaultOptions("").WithInMemory(m)
} else {
dir, err = os.MkdirTemp("", badgerFilePrefix)
if err != nil {
return nil, fmt.Errorf("error creating temporary key-value storage: %w", err)
Expand All @@ -192,8 +194,6 @@ func newBadgerStorage(m bool) (*badgerStorage, error) {
log.Output(1, fmt.Sprintf("Creating temporary key-value storage at %s", dir))
}
opt = badger.DefaultOptions(dir)
} else {
opt = badger.DefaultOptions("").WithInMemory(m)
}
db, err := badger.Open(opt.WithLogger(&badgerLogger{}))
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions transform/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ func saveUpdatedAt(db database, dir string) error {
// Transform the downloaded files for company venues creating a database record
// per CNPJ
func Transform(dir string, db database, maxParallelDBQueries, batchSize int, privacy, mem bool) error {
if err := saveUpdatedAt(db, dir); err != nil {
return fmt.Errorf("error saving the update at date: %w", err)
}
l, err := newLookups(dir)
if err != nil {
return fmt.Errorf("error creating look up tables from %s: %w", dir, err)
Expand All @@ -62,5 +59,8 @@ func Transform(dir string, db database, maxParallelDBQueries, batchSize int, pri
if err != nil {
return fmt.Errorf("error creating new task for venues in %s: %w", dir, err)
}
return j.run(maxParallelDBQueries)
if err := j.run(maxParallelDBQueries); err != nil {
return fmt.Errorf("error writing venues to database: %w", err)
}
return saveUpdatedAt(db, dir)
}

0 comments on commit 4689efb

Please sign in to comment.