forked from ALHP/ALHP.GO
query directly for package instead of going through all of them every single time
This commit is contained in:
21
utils.go
21
utils.go
@@ -6,6 +6,8 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
"entgo.io/ent/dialect/sql"
|
||||||
|
"entgo.io/ent/dialect/sql/sqljson"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/Jguer/go-alpm/v2"
|
"github.com/Jguer/go-alpm/v2"
|
||||||
paconf "github.com/Morganamilo/go-pacmanconf"
|
paconf "github.com/Morganamilo/go-pacmanconf"
|
||||||
@@ -615,7 +617,13 @@ func (path PKGFile) DBPackage(march string) (*ent.DbPackage, error) {
|
|||||||
fNameSplit := strings.Split(filepath.Base(string(path)), "-")
|
fNameSplit := strings.Split(filepath.Base(string(path)), "-")
|
||||||
pkgname := strings.Join(fNameSplit[:len(fNameSplit)-3], "-")
|
pkgname := strings.Join(fNameSplit[:len(fNameSplit)-3], "-")
|
||||||
|
|
||||||
dbPkgs, err := db.DbPackage.Query().Where(dbpackage.And(dbpackage.PackagesNotNil(), dbpackage.March(march))).All(context.Background())
|
dbPkg, err := db.DbPackage.Query().Where(func(s *sql.Selector) {
|
||||||
|
s.Where(
|
||||||
|
sql.And(
|
||||||
|
sqljson.ValueContains(dbpackage.FieldPackages, pkgname),
|
||||||
|
sql.EQ(dbpackage.FieldMarch, march)),
|
||||||
|
)
|
||||||
|
}).Only(context.Background())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
switch err.(type) {
|
switch err.(type) {
|
||||||
case *ent.NotFoundError:
|
case *ent.NotFoundError:
|
||||||
@@ -624,17 +632,8 @@ func (path PKGFile) DBPackage(march string) (*ent.DbPackage, error) {
|
|||||||
default:
|
default:
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
} else if len(dbPkgs) == 0 {
|
|
||||||
return nil, fmt.Errorf("package not found in DB: %s", pkgname)
|
|
||||||
} else {
|
|
||||||
for _, dbPkg := range dbPkgs {
|
|
||||||
if contains(dbPkg.Packages, pkgname) {
|
|
||||||
return dbPkg, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return dbPkg, nil
|
||||||
return nil, fmt.Errorf("package not found in DB: %s", pkgname)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (path PKGFile) isSignatureValid() (bool, error) {
|
func (path PKGFile) isSignatureValid() (bool, error) {
|
||||||
|
Reference in New Issue
Block a user