Skip to content

Commit

Permalink
fix(query): fix remote package slow filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
Jguer committed Nov 16, 2020
1 parent 8c4fe83 commit 8d9fed2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
1 change: 1 addition & 0 deletions pkg/db/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 22 additions & 4 deletions pkg/db/ialpm/alpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ import (
)

type AlpmExecutor struct {
handle *alpm.Handle
localDB alpm.IDB
syncDB alpm.IDBList
conf *pacmanconf.Config
handle *alpm.Handle
localDB alpm.IDB
syncDB alpm.IDBList
syncDBsCache []alpm.IDB
conf *pacmanconf.Config
}

func NewExecutor(pacmanConf *pacmanconf.Config) (*AlpmExecutor, error) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
23 changes: 9 additions & 14 deletions pkg/query/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@ 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
}
Expand All @@ -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, pkgName)
}
remote = append(remote, localpkg)
remoteNames = append(remoteNames, localpkg.Name())
}
return remote, remoteNames
}
Expand Down

0 comments on commit 8d9fed2

Please sign in to comment.