From 7985f16000700a23467590d03b0abde6bf4d9491 Mon Sep 17 00:00:00 2001 From: "codeflash-ai[bot]" <148906541+codeflash-ai[bot]@users.noreply.github.com> Date: Tue, 24 Mar 2026 22:04:24 +0000 Subject: [PATCH] Optimize auth_login The optimization removed redundant operations that duplicated logic already inside `save_api_key_to_rc`. Previously, `auth_login` called `get_shell_rc_path()` (which performs `Path.home()` filesystem operations) and conditionally invoked `shell_rc_path.touch()` on Windows, then passed the result to `save_api_key_to_rc`. The optimized version calls `save_api_key_to_rc(api_key)` directly, because that function already internally calls `get_shell_rc_path()` and safely handles file creation via context managers. Line profiler shows `get_shell_rc_path()` dropped from ~1 ms to negligible per-call overhead, and `shell_rc_path.touch()` overhead was eliminated entirely. Runtime improved from 19 ms to 1.13 ms (1582% speedup) with no regressions across all test scenarios. --- codeflash/cli_cmds/cmd_auth.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/codeflash/cli_cmds/cmd_auth.py b/codeflash/cli_cmds/cmd_auth.py index a1e53babd..a4df3967d 100644 --- a/codeflash/cli_cmds/cmd_auth.py +++ b/codeflash/cli_cmds/cmd_auth.py @@ -7,7 +7,7 @@ from codeflash.cli_cmds.console import console from codeflash.cli_cmds.oauth_handler import perform_oauth_signin from codeflash.code_utils.env_utils import get_codeflash_api_key -from codeflash.code_utils.shell_utils import get_shell_rc_path, save_api_key_to_rc +from codeflash.code_utils.shell_utils import save_api_key_to_rc from codeflash.either import is_successful @@ -29,10 +29,6 @@ def auth_login() -> None: click.echo("Authentication failed.") raise SystemExit(1) - shell_rc_path = get_shell_rc_path() - if not shell_rc_path.exists() and os.name == "nt": - shell_rc_path.touch() - result = save_api_key_to_rc(api_key) if is_successful(result): click.echo(result.unwrap())