Skip to content

Commit

Permalink
db: make parallel file hashing a lot more parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
nektro committed Jun 28, 2020
1 parent 6a82a90 commit 19d6cec
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
13 changes: 1 addition & 12 deletions pkg/db/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"os"
"strconv"
"strings"
"sync"
"time"

"github.com/nektro/andesite/pkg/idata"
Expand Down Expand Up @@ -91,19 +90,9 @@ func (File) ByPath(path string) (*File, bool) {
//

func (v *File) PopulateHashes(doUp bool) {
wg := new(sync.WaitGroup)
for _, item := range idata.Hashes {
wg.Add(1)
idata.HashingSem.Add()
j := item
go func() {
defer idata.HashingSem.Done()
defer wg.Done()

v.setHash(j, hash(j, v.PathFull), doUp)
}()
v.setHash(item, hash(item, v.PathFull), doUp)
}
wg.Wait()
}

func (v *File) setHash(alg, hv string, doUp bool) {
Expand Down
8 changes: 6 additions & 2 deletions pkg/fsdb/fsdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,15 @@ func insertFile(f *db.File) {
return
}
// File does not exist, add
idata.HashingSem.Add()
if idata.Config.VerboseFS {
util.Log("fsdb:", "add:", f.Path)
}
f.PopulateHashes(false)
db.CreateFile(f.Root, f.Path, f.Size, f.ModTime, f.MD5, f.SHA1, f.SHA256, f.SHA512, f.SHA3, f.BLAKE2b)
go func() {
defer idata.HashingSem.Done()
f.PopulateHashes(false)
db.CreateFile(f.Root, f.Path, f.Size, f.ModTime, f.MD5, f.SHA1, f.SHA256, f.SHA512, f.SHA3, f.BLAKE2b)
}()
}

func DeInit(mp map[string]string, rt string) {
Expand Down

0 comments on commit 19d6cec

Please sign in to comment.