made indexAll and retagAll atomic and faster

This commit is contained in:
ston1th 2019-08-27 21:36:35 +02:00
commit 5649acf6a8
6 changed files with 131 additions and 64 deletions

View file

@ -247,13 +247,21 @@ func indexHandler(ctx *Context) {
ctx.Redirect(core.IndexURI, http.StatusFound)
return
}
go func() {
for _, f := range ctx.Srv.FS.RecursiveFiles("/") {
if !ctx.Srv.DB.IsIndexed(f) {
scanFile(ctx.Srv, f)
if m, c, ok := ctx.Srv.DB.IndexMutex.Lock(); ok {
go func() {
defer ctx.Srv.DB.IndexMutex.Unlock()
files := ctx.Srv.FS.RecursiveFiles("/")
ctx.Srv.DB.IndexMutex.Set(uint64(len(files)))
for _, f := range files {
if !ctx.Srv.DB.IsIndexed(f) {
scanFile(ctx.Srv, f)
}
ctx.Srv.DB.IndexMutex.Inc()
}
}
}()
}()
} else {
ctx.Srv.Log.Printf("indexAll: indexing already in progress: %d/%d", c, m)
}
ctx.Redirect(core.IndexURI, http.StatusFound)
}
}
@ -726,8 +734,8 @@ func userTotpHandler(ctx *Context) {
func logsHandler(ctx *Context) {
ctx.Template("logsHandler")
ctx.Data = webData{
Title: "Scan Logs",
BodyTitle: "Scan Logs",
Title: "Logs",
BodyTitle: "Logs",
}
switch ctx.Method() {
case "GET":