Do not call exportStack twice on every update
@@ -111,7 +111,12 @@ func newUpCmd() *cobra.Command {
return result.FromError(fmt.Errorf("getting stack configuration: %w", err))
}
- targetURNs := []resource.URN{}
+ targetURNs, replaceURNs := []resource.URN{}, []resource.URN{}
+
+ if len(targets)+len(replaces)+len(targetReplaces) > 0 {
+ // This call to s.Snapshot adds latency s.Update below will call s.Snapshot again, presumably
+ // with the same result. Refactoring this or introducing a cache is a little tricky. For now:
+ // only call Snapshot twice if targets, replaces, or targetReplaces require it.
snap, err := s.Snapshot(ctx)
if err != nil {
return result.FromError(err)
@@ -120,7 +125,6 @@ func newUpCmd() *cobra.Command {
targetURNs = append(targetURNs, snap.GlobUrn(resource.URN(t))...)
}
- replaceURNs := []resource.URN{}
for _, r := range replaces {
replaceURNs = append(replaceURNs, snap.GlobUrn(resource.URN(r))...)
}
@@ -129,6 +133,7 @@ func newUpCmd() *cobra.Command {
targetURNs = append(targetURNs, snap.GlobUrn(resource.URN(tr))...)
replaceURNs = append(replaceURNs, snap.GlobUrn(resource.URN(tr))...)
}
+ }
if len(targetURNs) == 0 && len(targets)+len(targetReplaces) > 0 {
// Wildcards were used, but they all evaluated to empty. We don't
