Skip to content

Commit 81e3889

Browse files
committed
perf: skip network ops for lightweight commands (version, help)
PersistentPreRunE was running AutoUpgrade + RefreshPackagesFromRemote for every command including 'openboot version'. Both make network requests, causing noticeable lag for commands that don't need them. Skip both for 'version' and 'help' commands.
1 parent 7457ff1 commit 81e3889

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

internal/cli/root.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,17 @@ shell configuration, and macOS preferences.`,
4040
openboot snapshot --json > my-setup.json`,
4141
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
4242
config.SetClientVersion(version)
43-
updater.AutoUpgrade(version)
44-
config.RefreshPackagesFromRemote()
43+
44+
// Skip network operations for lightweight commands that don't
45+
// need the package catalog or auto-update check.
46+
lightweightCmds := map[string]bool{
47+
"version": true,
48+
"help": true,
49+
}
50+
if !lightweightCmds[cmd.Name()] {
51+
updater.AutoUpgrade(version)
52+
config.RefreshPackagesFromRemote()
53+
}
4554

4655
if cfg.Silent {
4756
if name := os.Getenv("OPENBOOT_GIT_NAME"); name != "" {

0 commit comments

Comments
 (0)