-c|--c now also displays time spent scanning for files

This commit is contained in:
Seednode 2022-10-20 14:50:42 -05:00
parent 15d925a6d0
commit 8e4c9c5e32
3 changed files with 12 additions and 8 deletions

View File

@ -24,11 +24,6 @@ var (
ErrNoImagesFound = fmt.Errorf("no supported image formats found") ErrNoImagesFound = fmt.Errorf("no supported image formats found")
) )
type Concurrency struct {
DirectoryScans chan int
FileScans chan int
}
type Files struct { type Files struct {
Mutex sync.Mutex Mutex sync.Mutex
List map[string][]string List map[string][]string
@ -237,6 +232,7 @@ func splitPath(path string) (*Path, error) {
p.Base = split[0][1] p.Base = split[0][1]
p.Number, err = strconv.Atoi(split[0][2]) p.Number, err = strconv.Atoi(split[0][2])
if err != nil { if err != nil {
return &Path{}, err return &Path{}, err
} }
@ -419,6 +415,7 @@ func prepareDirectories(files *Files, sort string) []string {
func pickFile(args []string, filters *Filters, sort string) (string, error) { func pickFile(args []string, filters *Filters, sort string) (string, error) {
stats := Stats{} stats := Stats{}
files := Files{} files := Files{}
files.List = make(map[string][]string) files.List = make(map[string][]string)
@ -426,20 +423,22 @@ func pickFile(args []string, filters *Filters, sort string) (string, error) {
concurrency.DirectoryScans = make(chan int, maxDirectoryScans) concurrency.DirectoryScans = make(chan int, maxDirectoryScans)
concurrency.FileScans = make(chan int, maxFileScans) concurrency.FileScans = make(chan int, maxFileScans)
startTime := time.Now()
getFileList(args, &files, filters, &stats, &concurrency) getFileList(args, &files, filters, &stats, &concurrency)
runTime := time.Since(startTime)
if Count { if Count {
fmt.Printf("Choosing from %v files (skipped %v) in %v directories\n", fmt.Printf("Scanned %v files (skipped %v) across %v directories in %v\n",
stats.GetFilesMatched(), stats.GetFilesMatched(),
stats.GetFilesSkipped(), stats.GetFilesSkipped(),
stats.GetDirectoriesMatched(), stats.GetDirectoriesMatched(),
runTime,
) )
} }
fileList := prepareDirectories(&files, sort) fileList := prepareDirectories(&files, sort)
rand.Seed(time.Now().UnixNano()) rand.Seed(time.Now().UnixNano())
rand.Shuffle(len(fileList), func(i, j int) { fileList[i], fileList[j] = fileList[j], fileList[i] }) rand.Shuffle(len(fileList), func(i, j int) { fileList[i], fileList[j] = fileList[j], fileList[i] })
for i := 0; i < len(fileList); i++ { for i := 0; i < len(fileList); i++ {

View File

@ -19,6 +19,11 @@ const (
maxFileScans MaxConcurrency = 256 maxFileScans MaxConcurrency = 256
) )
type Concurrency struct {
DirectoryScans chan int
FileScans chan int
}
var Count bool var Count bool
var Filter bool var Filter bool
var Port uint16 var Port uint16

View File

@ -10,7 +10,7 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
var Version = "0.17.0" var Version = "0.17.1"
func init() { func init() {
rootCmd.AddCommand(versionCmd) rootCmd.AddCommand(versionCmd)