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
Reduce Carvel response times for GetAvailablePackageSummaries #4378
Changes from 2 commits
65d1c36
2a4cb44
1f382a0
51fafb7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -203,9 +203,31 @@ func (s *Server) getApp(ctx context.Context, cluster, namespace, identifier stri | |
|
||
// List of resources getters | ||
|
||
// getPkgs returns the list of packages for the given cluster and namespace | ||
func (s *Server) getPkgs(ctx context.Context, cluster, namespace string) ([]*datapackagingv1alpha1.Package, error) { | ||
return s.getPkgsWithFieldSelector(ctx, cluster, namespace, "") | ||
// getPkgs requests the packages for the given cluster and namespace and sends | ||
// them to the channel to be processed immediately, closing the channel | ||
// when finished or when an error is returned. | ||
func (s *Server) getPkgs(ctx context.Context, cluster, namespace string, ch chan<- *datapackagingv1alpha1.Package) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function wasn't actually used at all, so I updated it to do what I want. Importantly, it does not iterate all the results into an in-memory slice, but rather sends each package down the return channel as it iterates (so we can process them while it continues iterating). The other important point here is, as mentioned in the comment, that this function guarantees to close the channel, so we can be sure when it has completed (or returned with an error). |
||
defer close(ch) | ||
resource, err := s.getPkgResource(ctx, cluster, namespace) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
unstructured, err := resource.List(ctx, metav1.ListOptions{}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, unstructured := range unstructured.Items { | ||
pkg := &datapackagingv1alpha1.Package{} | ||
err := runtime.DefaultUnstructuredConverter.FromUnstructured(unstructured.Object, pkg) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
ch <- pkg | ||
} | ||
return nil | ||
} | ||
|
||
// getPkgs returns the list of packages for the given cluster and namespace | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was no requirement for having the package map, just the latest version, which also means we don't need the ability to return an error here.