Merge pull request #225 from Morganamilo/develspeedup

Use goroutinuies for devel updates
This commit is contained in:
Morgana 2018-03-13 17:19:24 +00:00 committed by GitHub
commit b7eae565fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 68 additions and 25 deletions

View File

@ -338,21 +338,18 @@ func aurInfo(names []string) ([]rpc.Pkg, error) {
outOfDate := make([]string, 0, len(names))
makeRequest := func(n, max int) {
defer wg.Done()
tempInfo, requestErr := rpc.Info(names[n:max])
if err != nil {
wg.Done()
return
}
if requestErr != nil {
//return info, err
err = requestErr
wg.Done()
return
}
mux.Lock()
info = append(info, tempInfo...)
mux.Unlock()
wg.Done()
}
for n := 0; n < len(names); n += config.RequestSplitN {

View File

@ -5,6 +5,7 @@ import (
"fmt"
"os"
"sort"
"sync"
"unicode"
alpm "github.com/jguer/go-alpm"
@ -128,17 +129,40 @@ loop:
}
func upDevel(remote []alpm.Package, packageC chan upgrade, done chan bool) {
for vcsName, e := range savedInfo {
toUpdate := make([]alpm.Package, 0, 0)
toRemove := make([]string, 0, 0)
var mux1 sync.Mutex
var mux2 sync.Mutex
var wg sync.WaitGroup
checkUpdate := func(vcsName string, e shaInfos) {
defer wg.Done()
if e.needsUpdate() {
found := false
var pkg alpm.Package
for _, r := range remote {
if r.Name() == vcsName {
found = true
pkg = r
for _, pkg := range remote {
if pkg.Name() == vcsName {
mux1.Lock()
toUpdate = append(toUpdate, pkg)
mux1.Unlock()
return
}
}
if found {
mux2.Lock()
toRemove = append(toRemove, vcsName)
mux2.Unlock()
}
}
for vcsName, e := range savedInfo {
wg.Add(1)
go checkUpdate(vcsName, e)
}
wg.Wait()
for _, pkg := range toUpdate {
if pkg.ShouldIgnore() {
left, right := getVersionDiff(pkg.Version(), "latest-commit")
fmt.Print(magenta("Warning: "))
@ -146,11 +170,9 @@ func upDevel(remote []alpm.Package, packageC chan upgrade, done chan bool) {
} else {
packageC <- upgrade{pkg.Name(), "devel", pkg.Version(), "latest-commit"}
}
} else {
removeVCSPackage([]string{vcsName})
}
}
}
removeVCSPackage(toRemove)
done <- true
}

28
vcs.go
View File

@ -142,15 +142,39 @@ func getCommit(url string, branch string, protocols []string) string {
}
func (infos shaInfos) needsUpdate() bool {
for url, info := range infos {
//used to signal we have gone through all sources and found nothing
finished := make(chan struct{})
alive := 0
//if we find an update we use this to exit early and return true
hasUpdate := make(chan struct{})
checkHash := func(url string, info shaInfo) {
hash := getCommit(url, info.Brach, info.Protocols)
if hash != "" && hash != info.SHA {
return true
hasUpdate <- struct{}{}
} else {
finished <- struct{}{}
}
}
for url, info := range infos {
alive++
go checkHash(url, info)
}
for {
select {
case <- hasUpdate:
return true
case <- finished:
alive--
if alive == 0 {
return false
}
}
}
}
func inStore(pkgName string) shaInfos {
return savedInfo[pkgName]