Skip to content

Commit

Permalink
feat(db) no progress when --log-json option (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
sadayuki-matsuno authored Jul 4, 2024
1 parent 04189c0 commit 0c8a289
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
8 changes: 7 additions & 1 deletion db/rdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io"
"log"
"os"
"time"
Expand Down Expand Up @@ -183,7 +184,12 @@ func (r *RDBDriver) InsertMetasploit(records []models.Metasploit) (err error) {
}

func (r *RDBDriver) deleteAndInsertMetasploit(records []models.Metasploit) (err error) {
bar := pb.StartNew(len(records))
bar := pb.StartNew(len(records)).SetWriter(func() io.Writer {
if viper.GetBool("log-json") {
return io.Discard
}
return os.Stderr
}())
tx := r.conn.Begin()
defer func() {
if err != nil {
Expand Down
9 changes: 8 additions & 1 deletion db/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"encoding/json"
"errors"
"fmt"
"io"
"os"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -202,7 +204,12 @@ func (r *RedisDriver) InsertMetasploit(records []models.Metasploit) (err error)
}

log15.Info("Inserting Modules having CVEs...")
bar := pb.StartNew(len(records))
bar := pb.StartNew(len(records)).SetWriter(func() io.Writer {
if viper.GetBool("log-json") {
return io.Discard
}
return os.Stderr
}())
for idx := range chunkSlice(len(records), batchSize) {
pipe := r.conn.Pipeline()
for _, record := range records[idx.From:idx.To] {
Expand Down

0 comments on commit 0c8a289

Please sign in to comment.