mirror of
https://github.com/Jguer/yay
synced 2024-07-18 08:23:32 +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
|
PackagesFromGroup(string) []alpm.IPackage
|
||||||
RefreshHandle() error
|
RefreshHandle() error
|
||||||
RepoUpgrades(bool) (upgrade.UpSlice, error)
|
RepoUpgrades(bool) (upgrade.UpSlice, error)
|
||||||
|
SyncPackage(string) alpm.IPackage
|
||||||
SyncPackages(...string) []alpm.IPackage
|
SyncPackages(...string) []alpm.IPackage
|
||||||
SyncSatisfier(string) alpm.IPackage
|
SyncSatisfier(string) alpm.IPackage
|
||||||
SyncSatisfierExists(string) bool
|
SyncSatisfierExists(string) bool
|
||||||
|
|
|
@ -18,10 +18,11 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type AlpmExecutor struct {
|
type AlpmExecutor struct {
|
||||||
handle *alpm.Handle
|
handle *alpm.Handle
|
||||||
localDB alpm.IDB
|
localDB alpm.IDB
|
||||||
syncDB alpm.IDBList
|
syncDB alpm.IDBList
|
||||||
conf *pacmanconf.Config
|
syncDBsCache []alpm.IDB
|
||||||
|
conf *pacmanconf.Config
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewExecutor(pacmanConf *pacmanconf.Config) (*AlpmExecutor, error) {
|
func NewExecutor(pacmanConf *pacmanconf.Config) (*AlpmExecutor, error) {
|
||||||
|
@ -255,6 +256,7 @@ func (ae *AlpmExecutor) RefreshHandle() error {
|
||||||
alpmHandle.SetQuestionCallback(ae.questionCallback())
|
alpmHandle.SetQuestionCallback(ae.questionCallback())
|
||||||
alpmHandle.SetLogCallback(logCallback)
|
alpmHandle.SetLogCallback(logCallback)
|
||||||
ae.handle = alpmHandle
|
ae.handle = alpmHandle
|
||||||
|
ae.syncDBsCache = nil
|
||||||
ae.syncDB, err = alpmHandle.SyncDBs()
|
ae.syncDB, err = alpmHandle.SyncDBs()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -341,6 +343,22 @@ func (ae *AlpmExecutor) LocalPackage(pkgName string) alpm.IPackage {
|
||||||
return pkg
|
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 {
|
func (ae *AlpmExecutor) SatisfierFromDB(pkgName, dbName string) alpm.IPackage {
|
||||||
singleDB, err := ae.handle.SyncDBByName(dbName)
|
singleDB, err := ae.handle.SyncDBByName(dbName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -12,15 +12,13 @@ import (
|
||||||
|
|
||||||
// GetPackageNamesBySource returns package names with and without correspondence in SyncDBS respectively
|
// GetPackageNamesBySource returns package names with and without correspondence in SyncDBS respectively
|
||||||
func GetPackageNamesBySource(dbExecutor db.Executor) (local, remote []string, err error) {
|
func GetPackageNamesBySource(dbExecutor db.Executor) (local, remote []string, err error) {
|
||||||
outer:
|
|
||||||
for _, localpkg := range dbExecutor.LocalPackages() {
|
for _, localpkg := range dbExecutor.LocalPackages() {
|
||||||
for _, syncpkg := range dbExecutor.SyncPackages() {
|
pkgName := localpkg.Name()
|
||||||
if localpkg.Name() == syncpkg.Name() {
|
if dbExecutor.SyncPackage(pkgName) != nil {
|
||||||
local = append(local, localpkg.Name())
|
local = append(local, pkgName)
|
||||||
continue outer
|
} else {
|
||||||
}
|
remote = append(remote, pkgName)
|
||||||
}
|
}
|
||||||
remote = append(remote, localpkg.Name())
|
|
||||||
}
|
}
|
||||||
return local, remote, err
|
return local, remote, err
|
||||||
}
|
}
|
||||||
|
@ -29,15 +27,12 @@ outer:
|
||||||
func GetRemotePackages(dbExecutor db.Executor) (
|
func GetRemotePackages(dbExecutor db.Executor) (
|
||||||
remote []alpm.IPackage,
|
remote []alpm.IPackage,
|
||||||
remoteNames []string) {
|
remoteNames []string) {
|
||||||
outer:
|
|
||||||
for _, localpkg := range dbExecutor.LocalPackages() {
|
for _, localpkg := range dbExecutor.LocalPackages() {
|
||||||
for _, syncpkg := range dbExecutor.SyncPackages() {
|
pkgName := localpkg.Name()
|
||||||
if localpkg.Name() == syncpkg.Name() {
|
if dbExecutor.SyncPackage(pkgName) == nil {
|
||||||
continue outer
|
remote = append(remote, localpkg)
|
||||||
}
|
remoteNames = append(remoteNames, pkgName)
|
||||||
}
|
}
|
||||||
remote = append(remote, localpkg)
|
|
||||||
remoteNames = append(remoteNames, localpkg.Name())
|
|
||||||
}
|
}
|
||||||
return remote, remoteNames
|
return remote, remoteNames
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue