Skip to content

Commit

Permalink
Use searchVersion query param to GET packages (#15)
Browse files Browse the repository at this point in the history
Instead of GETing all packages, only return packages that match the
version name
  • Loading branch information
george-angel authored Mar 24, 2022
1 parent e88a722 commit 77add72
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
8 changes: 5 additions & 3 deletions internal/provider/data_source_package.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,17 @@ func dataSourcePackageRead(ctx context.Context, d *schema.ResourceData, meta int
return diag.FromErr(err)
}
d.Set("application_id", appID)
packagePage, err := c.ListPackages(appID)

version := d.Get("version").(string)
arch := d.Get("arch").(string)

packagePage, err := c.SearchPackages(appID, version)
if err != nil {
return diag.FromErr(err)
}
if packagePage.Count != packagePage.TotalCount {
return diag.FromErr(fmt.Errorf("GET packages returned %d/%d packages. We don't paginate.", packagePage.Count, packagePage.TotalCount))
}
version := d.Get("version").(string)
arch := d.Get("arch").(string)

for _, p := range packagePage.Packages {
if p.Version == version && api.Arch(p.Arch).String() == arch {
Expand Down
6 changes: 3 additions & 3 deletions nebraska/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ func (c *Client) GetPackage(appID, id string) (*codegen.Package, error) {
return data, nil
}

// ListPackages lists the packages for a particular application
func (c *Client) ListPackages(appID string) (*codegen.PackagePage, error) {
req, err := c.newRequest(http.MethodGet, fmt.Sprintf("/api/apps/%s/packages?page=1&perpage=10000", appID), nil)
// SearchPackages lists the packages for a particular application and version
func (c *Client) SearchPackages(appID, id string) (*codegen.PackagePage, error) {
req, err := c.newRequest(http.MethodGet, fmt.Sprintf("/api/apps/%s/packages?page=1&perpage=100000&searchVersion=%s", appID, id), nil)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 77add72

Please sign in to comment.