Only seed rng once, at initialization, and speed up picking random file by using rand.Intn instead of shuffling the slice
This commit is contained in:
parent
920bdb2615
commit
97e3b47b19
|
@ -495,13 +495,11 @@ func pickFile(args []string, filters *Filters, sort string, fileCache *[]string)
|
|||
}
|
||||
}
|
||||
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
rand.Shuffle(len(fileList), func(i, j int) { fileList[i], fileList[j] = fileList[j], fileList[i] })
|
||||
for true {
|
||||
i := rand.Intn(len(fileList))
|
||||
|
||||
for i := 0; i < len(fileList); i++ {
|
||||
filePath := fileList[i]
|
||||
|
||||
// If not caching, check for valid images just before serving, to speed up scanning
|
||||
if !Cache {
|
||||
isImage, err := isImage(filePath)
|
||||
if err != nil {
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var Version = "0.20.2"
|
||||
var Version = "0.20.3"
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(versionCmd)
|
||||
|
|
|
@ -7,6 +7,7 @@ package cmd
|
|||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
|
@ -498,6 +499,8 @@ func ServePage(args []string) error {
|
|||
|
||||
re := regexp.MustCompile(`(.+)([0-9]{3})(\..+)`)
|
||||
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
|
||||
fileCache := []string{}
|
||||
|
||||
http.Handle("/", serveHtmlHandler(paths, *re, &fileCache))
|
||||
|
|
Loading…
Reference in New Issue