mirror of
https://github.com/Jguer/yay.git
synced 2024-11-07 01:27:21 +01:00
Merge pull request #225 from Morganamilo/develspeedup
Use goroutinuies for devel updates
This commit is contained in:
commit
b7eae565fd
5
query.go
5
query.go
@ -338,21 +338,18 @@ func aurInfo(names []string) ([]rpc.Pkg, error) {
|
|||||||
outOfDate := make([]string, 0, len(names))
|
outOfDate := make([]string, 0, len(names))
|
||||||
|
|
||||||
makeRequest := func(n, max int) {
|
makeRequest := func(n, max int) {
|
||||||
|
defer wg.Done()
|
||||||
tempInfo, requestErr := rpc.Info(names[n:max])
|
tempInfo, requestErr := rpc.Info(names[n:max])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
wg.Done()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if requestErr != nil {
|
if requestErr != nil {
|
||||||
//return info, err
|
|
||||||
err = requestErr
|
err = requestErr
|
||||||
wg.Done()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
mux.Lock()
|
mux.Lock()
|
||||||
info = append(info, tempInfo...)
|
info = append(info, tempInfo...)
|
||||||
mux.Unlock()
|
mux.Unlock()
|
||||||
wg.Done()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for n := 0; n < len(names); n += config.RequestSplitN {
|
for n := 0; n < len(names); n += config.RequestSplitN {
|
||||||
|
58
upgrade.go
58
upgrade.go
@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"sort"
|
"sort"
|
||||||
|
"sync"
|
||||||
"unicode"
|
"unicode"
|
||||||
|
|
||||||
alpm "github.com/jguer/go-alpm"
|
alpm "github.com/jguer/go-alpm"
|
||||||
@ -128,29 +129,50 @@ loop:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func upDevel(remote []alpm.Package, packageC chan upgrade, done chan bool) {
|
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() {
|
if e.needsUpdate() {
|
||||||
found := false
|
for _, pkg := range remote {
|
||||||
var pkg alpm.Package
|
if pkg.Name() == vcsName {
|
||||||
for _, r := range remote {
|
mux1.Lock()
|
||||||
if r.Name() == vcsName {
|
toUpdate = append(toUpdate, pkg)
|
||||||
found = true
|
mux1.Unlock()
|
||||||
pkg = r
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if found {
|
|
||||||
if pkg.ShouldIgnore() {
|
mux2.Lock()
|
||||||
left, right := getVersionDiff(pkg.Version(), "latest-commit")
|
toRemove = append(toRemove, vcsName)
|
||||||
fmt.Print(magenta("Warning: "))
|
mux2.Unlock()
|
||||||
fmt.Printf("%s ignoring package upgrade (%s => %s)\n", cyan(pkg.Name()), left, right)
|
|
||||||
} else {
|
|
||||||
packageC <- upgrade{pkg.Name(), "devel", pkg.Version(), "latest-commit"}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
removeVCSPackage([]string{vcsName})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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: "))
|
||||||
|
fmt.Printf("%s ignoring package upgrade (%s => %s)\n", cyan(pkg.Name()), left, right)
|
||||||
|
} else {
|
||||||
|
packageC <- upgrade{pkg.Name(), "devel", pkg.Version(), "latest-commit"}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
removeVCSPackage(toRemove)
|
||||||
done <- true
|
done <- true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
30
vcs.go
30
vcs.go
@ -142,14 +142,38 @@ func getCommit(url string, branch string, protocols []string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (infos shaInfos) needsUpdate() bool {
|
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)
|
hash := getCommit(url, info.Brach, info.Protocols)
|
||||||
if hash != "" && hash != info.SHA {
|
if hash != "" && hash != info.SHA {
|
||||||
return true
|
hasUpdate <- struct{}{}
|
||||||
|
} else {
|
||||||
|
finished <- struct{}{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
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 {
|
func inStore(pkgName string) shaInfos {
|
||||||
|
Loading…
Reference in New Issue
Block a user