Skip to content

Commit

Permalink
only operate on latest file in transform accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
Hbbb committed Feb 6, 2024
1 parent 400a8fe commit 415538a
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions cli/internal/domain/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"path/filepath"
"strings"
"time"

"github.com/gocarina/gocsv"
"github.com/plaid/plaid-go/v20/plaid"
Expand Down Expand Up @@ -126,6 +127,9 @@ func TransformTransactions(ctx context.Context, jsonStorage string, csvStorage s

func TransformAccounts(ctx context.Context, jsonStorage string, csvStorage string) error {
var accountsCSV []Account
var newestFile os.DirEntry
var newestTime time.Time

accountsPath := fmt.Sprintf("%s/accounts", jsonStorage)

err := filepath.WalkDir(accountsPath, func(path string, d os.DirEntry, err error) error {
Expand All @@ -137,6 +141,19 @@ func TransformAccounts(ctx context.Context, jsonStorage string, csvStorage strin
return nil
}

// Find the newest file in this directory
// If this isn't the newest file, skip import on this iteration
info, err := d.Info()
if err != nil {
return err
}
if newestFile == nil || info.ModTime().After(newestTime) {
newestFile = d
newestTime = info.ModTime()
} else {
return nil
}

bytes, err := os.ReadFile(path)
if err != nil {
return err
Expand Down

0 comments on commit 415538a

Please sign in to comment.