Skip to content

Commit

Permalink
Return pointer rather than instance on read of PackageRevision from db
Browse files Browse the repository at this point in the history
  • Loading branch information
liamfallon committed Nov 5, 2024
1 parent 9751228 commit bc0845b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions pkg/db/dbpackagerevisionsql.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ func pkgRevReadFromDB(prk repository.PackageRevisionKey) (dbPackageRevision, err
return dbPkgRev, err
}

func pkgRevReadPRsFromDB(pk repository.PackageKey) ([]dbPackageRevision, error) {
func pkgRevReadPRsFromDB(pk repository.PackageKey) ([]*dbPackageRevision, error) {
sqlStatement := `SELECT * FROM package_revisions WHERE namespace=$1 AND repo_name=$2 AND package_name=$3`

var dbPkgRevs []dbPackageRevision
var dbPkgRevs []*dbPackageRevision

klog.Infof("pkgReadPRsFromDB: running query [%q] on %q", sqlStatement, pk)

Expand Down Expand Up @@ -98,7 +98,7 @@ func pkgRevReadPRsFromDB(pk repository.PackageKey) ([]dbPackageRevision, error)
klog.Infof("pkgRevReadFromDB: reading package revision resources %q returned err: %q", pkgRev.Key(), err)
}

dbPkgRevs = append(dbPkgRevs, pkgRev)
dbPkgRevs = append(dbPkgRevs, &pkgRev)
}

return dbPkgRevs, nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/db/dbrepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (r dbRepository) ListPackageRevisions(ctx context.Context, filter repositor
return nil, err
}

var foundPkgRevs []dbPackageRevision
var foundPkgRevs []*dbPackageRevision

for _, pkg := range pkgs {
pkgRevs, err := pkgRevReadPRsFromDB(pkg.Key())
Expand Down
6 changes: 3 additions & 3 deletions pkg/registry/porch/name.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ func ParseRepositoryName(name string) (string, error) {
if strings.Contains(name, ".") {
// New type of parseable package revision name
parsedName := strings.Split(name, ".")
if len(parsedName) != 5 {
return "", fmt.Errorf("malformed package revision name; expected five elements delimited by \".\" characters: %q", name)
if len(parsedName) != 4 {
return "", fmt.Errorf("malformed package revision name; expected 4 elements delimited by \".\" characters: %q", name)
}
return parsedName[1], nil
return parsedName[0], nil
} else {
// Old type of package revision name
lastDash := strings.LastIndex(name, "-")
Expand Down

0 comments on commit bc0845b

Please sign in to comment.