mirror of
https://github.com/Jguer/yay.git
synced 2024-11-07 01:27:21 +01:00
Finished new upgrade mechanism. Benchmarks show improved performance.
=== RUN TestSearch --- PASS: TestSearch (0.38s) === RUN TestInfo --- PASS: TestInfo (0.08s) === RUN TestUpdate :: Starting AUR upgrade... ==> arduino: 1:1.6.12-3 -> 1:1.6.12-4 ==> Proceed with upgrade (Y/n) ==> Installing arduino ==> Edit PKGBUILD? (y/N) --- PASS: TestUpdate (1.15s) === RUN TestUpgrade :: Starting AUR upgrade... ==> arduino: 1:1.6.12-4 -> 1:1.6.12-3 ==> Proceed with upgrade (Y/n) ==> Installing arduino ==> Edit PKGBUILD? (y/N) --- PASS: TestUpgrade (1.07s) PASS BenchMark Update 2 1022581207 ns/op 2034108 B/op 14345 allocs/op BenchMark Upgrade 2 956533245 ns/op 662720 B/op 11738 allocs/op
This commit is contained in:
parent
721b7c9ebb
commit
20a98de384
83
aur/aur.go
83
aur/aur.go
@ -118,6 +118,24 @@ func Info(pkg string) (Query, int, error) {
|
|||||||
return r.Results, r.ResultCount, err
|
return r.Results, r.ResultCount, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MultiInfo takes a slice of strings and returns a slice with the info of each package
|
||||||
|
func MultiInfo(pkgS []string) (Query, int, error) {
|
||||||
|
type returned struct {
|
||||||
|
Results Query `json:"results"`
|
||||||
|
ResultCount int `json:"resultcount"`
|
||||||
|
}
|
||||||
|
r := returned{}
|
||||||
|
|
||||||
|
var pkg string
|
||||||
|
for _, pkgn := range pkgS {
|
||||||
|
pkg += "&arg[]=" + pkgn
|
||||||
|
}
|
||||||
|
|
||||||
|
err := getJSON("https://aur.archlinux.org/rpc/?v=5&type=info"+pkg, &r)
|
||||||
|
|
||||||
|
return r.Results, r.ResultCount, err
|
||||||
|
}
|
||||||
|
|
||||||
// Install sends system commands to make and install a package from pkgName
|
// Install sends system commands to make and install a package from pkgName
|
||||||
func Install(pkg string, baseDir string, conf *alpm.PacmanConfig, flags []string) (err error) {
|
func Install(pkg string, baseDir string, conf *alpm.PacmanConfig, flags []string) (err error) {
|
||||||
q, n, err := Info(pkg)
|
q, n, err := Info(pkg)
|
||||||
@ -137,53 +155,38 @@ func Install(pkg string, baseDir string, conf *alpm.PacmanConfig, flags []string
|
|||||||
func Upgrade(baseDir string, conf *alpm.PacmanConfig, flags []string) error {
|
func Upgrade(baseDir string, conf *alpm.PacmanConfig, flags []string) error {
|
||||||
fmt.Println("\x1b[1;36;1m::\x1b[0m\x1b[1m Starting AUR upgrade...\x1b[0m")
|
fmt.Println("\x1b[1;36;1m::\x1b[0m\x1b[1m Starting AUR upgrade...\x1b[0m")
|
||||||
|
|
||||||
foreign, err := pacman.ForeignPackages()
|
foreign, n, err := pacman.ForeignPackages()
|
||||||
|
if err != nil || n == 0 {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
keys := make([]string, len(foreign))
|
||||||
|
|
||||||
|
i := 0
|
||||||
|
for k := range foreign {
|
||||||
|
keys[i] = k
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
|
||||||
|
q, _, err := MultiInfo(keys)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find outdated packages
|
outdated := q[:0]
|
||||||
type Outdated struct {
|
for _, res := range q {
|
||||||
res *Result
|
if _, ok := foreign[res.Name]; ok {
|
||||||
pkgVersion string
|
|
||||||
er error
|
|
||||||
}
|
|
||||||
|
|
||||||
r := make(chan *Outdated) // Allocate a channel.
|
|
||||||
for name, info := range foreign {
|
|
||||||
// fmt.Println("Checking number", i, pkg.Name())
|
|
||||||
go func(name string, date int64, version string) {
|
|
||||||
q, n, err := Info(name)
|
|
||||||
if err != nil {
|
|
||||||
r <- nil
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if n == 0 {
|
|
||||||
r <- nil
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Leaving this here for now, warn about downgrades later
|
// Leaving this here for now, warn about downgrades later
|
||||||
if int64(q[0].LastModified) > date {
|
if res.LastModified > foreign[res.Name].Date {
|
||||||
r <- &Outdated{&q[0], version, err}
|
// o[i] = o[len(o)-1]
|
||||||
} else {
|
// o[len(o)-1] = Result{} // Trying to help the GC, not sure if necessary. Time will tell
|
||||||
r <- nil
|
// o = o[:len(o)-1]
|
||||||
|
fmt.Printf("\x1b[1m\x1b[32m==>\x1b[33;1m %s: \x1b[0m%s \x1b[33;1m-> \x1b[0m%s\n",
|
||||||
|
res.Name, res.Version, foreign[res.Name].Version)
|
||||||
|
outdated = append(outdated, res)
|
||||||
}
|
}
|
||||||
}(name, info.Date, info.Version)
|
|
||||||
}
|
|
||||||
|
|
||||||
var outdated []*Result
|
|
||||||
var checkedPkg *Outdated
|
|
||||||
for i := 0; i < len(foreign); i++ {
|
|
||||||
// fmt.Println("Wait Cycle", i)
|
|
||||||
checkedPkg = <-r
|
|
||||||
// fmt.Println(checkedPkg)
|
|
||||||
if checkedPkg != nil {
|
|
||||||
fmt.Printf("\x1b[1m\x1b[32m==>\x1b[33;1m %s: \x1b[0m%s \x1b[33;1m-> \x1b[0m%s\n",
|
|
||||||
checkedPkg.res.Name, checkedPkg.pkgVersion, checkedPkg.res.Version)
|
|
||||||
outdated = append(outdated, checkedPkg.res)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//If there are no outdated packages, don't prompt
|
//If there are no outdated packages, don't prompt
|
||||||
|
@ -90,9 +90,40 @@ func TestUpgrade(t *testing.T) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = UpdatePackages("/tmp/yaytmp", &conf, []string{})
|
err = Upgrade("/tmp/yaytmp", &conf, []string{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Expected err to be nil but it was %s", err)
|
t.Fatalf("Expected err to be nil but it was %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BenchmarkUpdate(b *testing.B) {
|
||||||
|
var conf alpm.PacmanConfig
|
||||||
|
file, err := os.Open("/etc/pacman.conf")
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
conf, err = alpm.ParseConfig(file)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for n := 0; n < b.N; n++ {
|
||||||
|
UpdatePackages("/tmp/yaytmp", &conf, []string{})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkUpgrade(b *testing.B) {
|
||||||
|
var conf alpm.PacmanConfig
|
||||||
|
file, err := os.Open("/etc/pacman.conf")
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
conf, err = alpm.ParseConfig(file)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for n := 0; n < b.N; n++ {
|
||||||
|
Upgrade("/tmp/yaytmp", &conf, []string{})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user