Skip to content

Commit f188a50

Browse files
authored
feat: apps init speed improvements (#4678)
## Changes Speed up `databricks apps init` by parallelizing three slow I/O operations (template cloning, npm install, resource list fetching) that previously ran sequentially, so they overlap with user interaction time. ### Main changes **Background template cloning** (`cmd/apps/init.go`): Template cloning now starts in a background goroutine immediately when the command runs, while the user is typing the project name. `resolveTemplateAsync` returns a channel; `awaitTemplate` either returns instantly (if already done) or shows a spinner for the remaining wait. This replaces the previous blocking `resolveTemplate` call that happened after the name prompt. **Background npm install** (`cmd/apps/init.go`): For Node.js templates, `startBackgroundNpmInstall` copies `package.json`/`package-lock.json` into the destination and kicks off `npm ci` while the user answers plugin/resource prompts. The result is awaited before template files are written to avoid concurrent writes. The Node.js initializer now skips redundant installs when `node_modules` already exists. **Prefetched resource lists** (`libs/apps/prompt/prefetch.go`, `libs/apps/prompt/prompt.go`): `PrefetchResources` fires background goroutines to fetch the first page of every resource type the manifest might need (warehouses, jobs, endpoints, experiments, Genie spaces, etc.) before the user selects plugins. A `ResourceCache` in the context stores `PagedFetcher` instances, so pickers render instantly when reached. Resource prompts now use `promptFromPagedFetcher` with "Load more..." and "Enter manually" / server-side search fallbacks, replacing the old `promptForResourceFromLister` that fetched everything in one blocking call. **Paged resource picker UX** (`libs/apps/prompt/prompt.go`, `libs/apps/prompt/listers.go`): All resource prompts switched from loading everything upfront to incremental paging (200 items/page, 10,000 cap). When capped, users can enter a name/ID manually or trigger a server-side search (currently supported for Jobs). Prompt titles now include the plugin display name for context (e.g. "Select SQL Warehouse for Analytics"). ### Supporting infrastructure - **`libs/apps/prompt/paged.go`** — `PagedFetcher` struct with `WaitForFirstPage`, `LoadMore`, `IsDone`, and a generic `collectN` helper for SDK iterators. - **`libs/apps/prompt/cache.go`** — Thread-safe `ResourceCache` stored in `context.Context` via `ContextWithCache`/`CacheFromContext`. - **`libs/apps/prompt/prefetch.go`** — Maps resource types to paged constructors and launches background prefetch goroutines for both single-step and multi-step (catalog/instance/project) resources. - **`libs/apps/prompt/listers.go`** — Added `NewPaged*` constructors for all resource types and a `SearchJobs` server-side search function. ### Other changes - Brand colors extracted into package-level `colorRed`/`colorGray`/`colorYellow`/`colorOrange` variables for consistency. - Filter hint changed from "type to filter" to "/ to filter" and explicit `.Filtering(true)` removed. - Volume IDs changed from `catalog.schema.volume` to `/Volumes/catalog/schema/volume`. - `manifest.Resource` gained a `PluginDisplayName` field (JSON-excluded) set during collection. - `manifest.Manifest` gained a `GetPluginNames` helper. - Checkmark output (`✔`/`✓`) consolidated into `prompt.PrintDone` across `deploy_bundle.go`, `import.go`, and `init.go`. - Existing `List*` functions now consistently apply `capResults` and use `min(len, maxListResults)` for initial slice capacity. ## Why <!-- Why are these changes needed? Provide the context that the reviewer might be missing. For example, were there any decisions behind the change that are not reflected in the code itself? --> ## Tests <!-- How have you tested the changes? --> <!-- If your PR needs to be included in the release notes for next release, add a separate entry in NEXT_CHANGELOG.md as part of your PR. --> --------- Co-authored-by: MarioCadenas <MarioCadenas@users.noreply.github.com>
1 parent c5f4546 commit f188a50

File tree

14 files changed

+1414
-344
lines changed

14 files changed

+1414
-344
lines changed

cmd/apps/deploy_bundle.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/databricks/cli/bundle/run"
1313
"github.com/databricks/cli/cmd/bundle/utils"
1414
"github.com/databricks/cli/cmd/root"
15+
"github.com/databricks/cli/libs/apps/prompt"
1516
"github.com/databricks/cli/libs/apps/validation"
1617
"github.com/databricks/cli/libs/cmdio"
1718
"github.com/databricks/cli/libs/log"
@@ -153,11 +154,11 @@ func runBundleDeploy(cmd *cobra.Command, force, skipValidation, skipTests bool)
153154

154155
log.Infof(ctx, "Running app: %s", appKey)
155156
if err := runBundleApp(ctx, b, appKey); err != nil {
156-
cmdio.LogString(ctx, "Deployment succeeded, but failed to start app")
157+
prompt.PrintDone(ctx, "Deployment succeeded, but failed to start app")
157158
return fmt.Errorf("failed to run app: %w. Run `databricks apps logs` to view logs", err)
158159
}
159160

160-
cmdio.LogString(ctx, "Deployment complete!")
161+
prompt.PrintDone(ctx, "Deployment complete!")
161162
return nil
162163
}
163164

cmd/apps/import.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"github.com/databricks/cli/bundle/run"
2121
bundleutils "github.com/databricks/cli/cmd/bundle/utils"
2222
"github.com/databricks/cli/cmd/root"
23+
"github.com/databricks/cli/libs/apps/prompt"
2324
"github.com/databricks/cli/libs/cmdctx"
2425
"github.com/databricks/cli/libs/cmdio"
2526
"github.com/databricks/cli/libs/dyn"
@@ -202,9 +203,10 @@ Examples:
202203
}
203204

204205
if !quiet {
205-
cmdio.LogString(ctx, fmt.Sprintf("\n✓ App '%s' has been successfully imported to %s", name, outputDir))
206+
cmdio.LogString(ctx, "")
207+
prompt.PrintDone(ctx, fmt.Sprintf("App '%s' imported to %s", name, outputDir))
206208
if cleanup && oldSourceCodePath != "" {
207-
cmdio.LogString(ctx, "Previous app folder has been cleaned up")
209+
prompt.PrintDone(ctx, "Previous app folder cleaned up")
208210
}
209211
cmdio.LogString(ctx, "\nYou can now deploy changes with: databricks bundle deploy")
210212
}

0 commit comments

Comments
 (0)