Cached mode now generates cache on first run, not first HTTP request, to improve initial response time
This commit is contained in:
parent
7929209eed
commit
19fa332ced
|
@ -10,7 +10,7 @@ import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Version = "0.29.0"
|
var Version = "0.29.1"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
rootCmd.AddCommand(versionCmd)
|
rootCmd.AddCommand(versionCmd)
|
||||||
|
|
15
cmd/web.go
15
cmd/web.go
|
@ -59,6 +59,14 @@ func (f *Filters) GetExcludes() string {
|
||||||
return strings.Join(f.Excludes, ",")
|
return strings.Join(f.Excludes, ",")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func generateCache(args []string, fileCache *[]string) error {
|
||||||
|
filters := &Filters{}
|
||||||
|
fmt.Printf("%v | Preparing image cache...\n", time.Now().Format(LogDate))
|
||||||
|
_, err := pickFile(args, filters, "", fileCache)
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
func notFound(w http.ResponseWriter, r *http.Request, filePath string) error {
|
func notFound(w http.ResponseWriter, r *http.Request, filePath string) error {
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
|
|
||||||
|
@ -443,6 +451,13 @@ func ServePage(args []string) error {
|
||||||
|
|
||||||
fileCache := &[]string{}
|
fileCache := &[]string{}
|
||||||
|
|
||||||
|
if Cache {
|
||||||
|
err := generateCache(args, fileCache)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
http.Handle("/", serveHtmlHandler(paths, regexes, fileCache))
|
http.Handle("/", serveHtmlHandler(paths, regexes, fileCache))
|
||||||
http.Handle(Prefix+"/", http.StripPrefix(Prefix, serveStaticFileHandler(paths)))
|
http.Handle(Prefix+"/", http.StripPrefix(Prefix, serveStaticFileHandler(paths)))
|
||||||
http.HandleFunc("/favicon.ico", doNothing)
|
http.HandleFunc("/favicon.ico", doNothing)
|
||||||
|
|
Loading…
Reference in New Issue