Skip to content

[search] Update search endpoints #1249

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jul 6, 2023
Merged

[search] Update search endpoints #1249

merged 9 commits into from
Jul 6, 2023

Conversation

mikeland73
Copy link
Contributor

@mikeland73 mikeland73 commented Jul 3, 2023

Summary

This updates search endpoints to use new v1 endpoints. It's a fairly small change, but required modernizing the format we use to unmarshal results. I took advantage to make a few low risk refactoring changes:

  • Removed lock dependency from search. This allows lock to have an actual searcher instance and not an interface.
  • Removed devpkgutil package and incorporated to searcher.
  • Improved search command to truncate results/versions to improve ui/ux. Added flag to show all commands.
  • Improved search command by allowing version to be specified to get a preview of what it will resolve to. This can be improved by doing server side filtering and using search instead of resolve.
  • Fixed devbox update bug where updating was causing lock files entries to get replaced even if version had not changed. (This causes nixpkgs to change which slows stuff down)

How was it tested?

  • Ran devbox update
  • Tested devbox add [email protected]
  • Tested devbox search with many values, with and without the --show-all flag
image

@mikeland73 mikeland73 marked this pull request as ready for review July 4, 2023 00:18
@mikeland73 mikeland73 requested review from savil and gcurtis July 5, 2023 20:20
Copy link
Collaborator

@savil savil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome! Please land asap so I can build on it :)

}
fmt.Fprintf(
cmd.OutOrStdout(),
"%s results to: %s@%s\n",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: results => resolves ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe I don't follow this scenario. This will occur for: devbox search [email protected], right?

And the output will be: [email protected] results to: [email protected] ??? This seems a bit ... odd.

I'm missing something...

return command
}

func printSearchResults(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the Test Plan, it would be good to copy-paste examples of the output from this function. It's hard to imagine in my head...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kind of get it...but for future PRs, consider this a request.

)

// FetchResolvedPackage fetches a resolution but does not write it to the lock
// struct. This allows testing new versions of packages without writing to the
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how and why would one test new versions of packages?


sysInfos := map[string]*SystemInfo{}
if featureflag.RemoveNixpkgs.Enabled() {
sysInfos = buildLockSystemInfos(*packageVersion)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why dereference, instead of passing the pointer in?

func WithVersion(version string) SearchOption {
return func() string {
return "&v=" + url.QueryEscape(version)
func (c *client) Resolve(name, version string) (*PackageVersion, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you add a doc-block comment for what resolve does?

}

func execSearch(url string) (*SearchResult, error) {
func execGet[T any](url string) (*T, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏾 I feel my programming brain has gotten too comfortable with golang when a simple thing like templates feels novel again :p

Version: packageInfo.Version,
Systems: sysInfos,
}, nil
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, wow, this is much cleaner than the old code!

Also, a 100 bonus points for having the searcher functions return searcher structs, and transforming them into lock structs here. I was also thinking of doing that.

@mikeland73 mikeland73 merged commit 0a280d1 into main Jul 6, 2023
@mikeland73 mikeland73 deleted the landau/new-endpoints branch July 6, 2023 04:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants