mirror of
https://github.com/Jguer/yay
synced 2024-10-05 23:59:13 +00:00
fix(query): fix remote package slow filtering
This commit is contained in:
parent
8c4fe837d3
commit
8d9fed2ad0
|
@ -26,6 +26,7 @@ type Executor interface {
|
|||
PackagesFromGroup(string) []alpm.IPackage
|
||||
RefreshHandle() error
|
||||
RepoUpgrades(bool) (upgrade.UpSlice, error)
|
||||
SyncPackage(string) alpm.IPackage
|
||||
SyncPackages(...string) []alpm.IPackage
|
||||
SyncSatisfier(string) alpm.IPackage
|
||||
SyncSatisfierExists(string) bool
|
||||
|
|
|
@ -21,6 +21,7 @@ type AlpmExecutor struct {
|
|||
handle *alpm.Handle
|
||||
localDB alpm.IDB
|
||||
syncDB alpm.IDBList
|
||||
syncDBsCache []alpm.IDB
|
||||
conf *pacmanconf.Config
|
||||
}
|
||||
|
||||
|
@ -255,6 +256,7 @@ func (ae *AlpmExecutor) RefreshHandle() error {
|
|||
alpmHandle.SetQuestionCallback(ae.questionCallback())
|
||||
alpmHandle.SetLogCallback(logCallback)
|
||||
ae.handle = alpmHandle
|
||||
ae.syncDBsCache = nil
|
||||
ae.syncDB, err = alpmHandle.SyncDBs()
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -341,6 +343,22 @@ func (ae *AlpmExecutor) LocalPackage(pkgName string) alpm.IPackage {
|
|||
return pkg
|
||||
}
|
||||
|
||||
func (ae *AlpmExecutor) syncDBs() []alpm.IDB {
|
||||
if ae.syncDBsCache == nil {
|
||||
ae.syncDBsCache = ae.syncDB.Slice()
|
||||
}
|
||||
return ae.syncDBsCache
|
||||
}
|
||||
|
||||
func (ae *AlpmExecutor) SyncPackage(pkgName string) alpm.IPackage {
|
||||
for _, db := range ae.syncDBs() {
|
||||
if dbPkg := db.Pkg(pkgName); dbPkg != nil {
|
||||
return dbPkg
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ae *AlpmExecutor) SatisfierFromDB(pkgName, dbName string) alpm.IPackage {
|
||||
singleDB, err := ae.handle.SyncDBByName(dbName)
|
||||
if err != nil {
|
||||
|
|
|
@ -12,16 +12,14 @@ import (
|
|||
|
||||
// GetPackageNamesBySource returns package names with and without correspondence in SyncDBS respectively
|
||||
func GetPackageNamesBySource(dbExecutor db.Executor) (local, remote []string, err error) {
|
||||
outer:
|
||||
for _, localpkg := range dbExecutor.LocalPackages() {
|
||||
for _, syncpkg := range dbExecutor.SyncPackages() {
|
||||
if localpkg.Name() == syncpkg.Name() {
|
||||
local = append(local, localpkg.Name())
|
||||
continue outer
|
||||
pkgName := localpkg.Name()
|
||||
if dbExecutor.SyncPackage(pkgName) != nil {
|
||||
local = append(local, pkgName)
|
||||
} else {
|
||||
remote = append(remote, pkgName)
|
||||
}
|
||||
}
|
||||
remote = append(remote, localpkg.Name())
|
||||
}
|
||||
return local, remote, err
|
||||
}
|
||||
|
||||
|
@ -29,15 +27,12 @@ outer:
|
|||
func GetRemotePackages(dbExecutor db.Executor) (
|
||||
remote []alpm.IPackage,
|
||||
remoteNames []string) {
|
||||
outer:
|
||||
for _, localpkg := range dbExecutor.LocalPackages() {
|
||||
for _, syncpkg := range dbExecutor.SyncPackages() {
|
||||
if localpkg.Name() == syncpkg.Name() {
|
||||
continue outer
|
||||
}
|
||||
}
|
||||
pkgName := localpkg.Name()
|
||||
if dbExecutor.SyncPackage(pkgName) == nil {
|
||||
remote = append(remote, localpkg)
|
||||
remoteNames = append(remoteNames, localpkg.Name())
|
||||
remoteNames = append(remoteNames, pkgName)
|
||||
}
|
||||
}
|
||||
return remote, remoteNames
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue