Skip to content

Commit a53fa22

Browse files
feat: performance improvement
1 parent 9249ba0 commit a53fa22

File tree

10 files changed

+114
-217
lines changed

10 files changed

+114
-217
lines changed

src/commands/daily.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import typer
22

3-
from ..server.api import get_daily_question
4-
from .edit import edit
5-
63

74
def daily(
85
lang: str = typer.Argument("py", help="Programming language to use."),
@@ -18,6 +15,8 @@ def daily(
1815
Fetches the daily coding challenge, displays problem details,
1916
and opens it in your preferred editor.
2017
"""
18+
from ..server.api import get_daily_question
19+
from .edit import edit
2120
from .show import show
2221

2322
if editor not in ["code", "vim", "nano"]:

src/commands/edit.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,6 @@
33

44
import typer
55

6-
from ..server.auth import Auth
7-
from ..server.config import LANGUAGE_MAP
8-
from ..server.solution_manager import SolutionManager
9-
from .show import _save_problem_to_file
10-
11-
solution_manager = SolutionManager(Auth().get_session())
12-
136

147
def edit(
158
problem: str = typer.Argument(..., help="Problem name or id."),
@@ -19,6 +12,13 @@ def edit(
1912
),
2013
):
2114
"""Solves a problem by passing lang param and open it with your code editor."""
15+
from ..server.auth import Auth
16+
from ..server.config import LANGUAGE_MAP
17+
from ..server.solution_manager import SolutionManager
18+
from .show import _save_problem_to_file
19+
20+
solution_manager = SolutionManager(Auth().get_session())
21+
2222
question_data = (
2323
solution_manager.get_question_data(problem).get("data", {}).get("question")
2424
)

src/commands/list_problems.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
11
from typing import Optional
22

33
import typer
4-
from rich.progress import Progress, SpinnerColumn, TextColumn
5-
6-
from ..lib.profile_ui import display_problem_list
7-
from ..server.api import fetch_problem_list
8-
from ..server.auth import Auth
94

105
status_map = {
116
"attempted": "TRIED",
127
"solved": "AC",
138
"todo": "NOT_STARTED",
149
}
1510

16-
AuthManager = Auth()
17-
1811

1912
def list_problems(
2013
difficulty: Optional[str] = typer.Option(
@@ -31,6 +24,15 @@ def list_problems(
3124
),
3225
):
3326
"""List available LeetCode problems with optional filters."""
27+
28+
from rich.progress import Progress, SpinnerColumn, TextColumn
29+
30+
from ..lib.profile_ui import display_problem_list
31+
from ..server.api import fetch_problem_list
32+
from ..server.auth import Auth
33+
34+
AuthManager = Auth()
35+
3436
if difficulty is not None or status is not None or tag is not None:
3537
if not AuthManager.is_authenticated:
3638
typer.echo(

src/commands/login.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import typer
22

3-
from ..server.auth import Auth
4-
5-
auth_manager = Auth()
6-
73

84
def login():
95
"""Login to LeetCode"""
6+
from ..server.auth import Auth
7+
8+
auth_manager = Auth()
9+
1010
if auth_manager.is_authenticated:
1111
saved_session = auth_manager.session_manager.load_session()
1212
if saved_session:
@@ -66,6 +66,11 @@ def login():
6666

6767
def logout():
6868
"""Logout from LeetCode"""
69+
70+
from ..server.auth import Auth
71+
72+
auth_manager = Auth()
73+
6974
if not auth_manager.is_authenticated:
7075
typer.echo(typer.style("❌ You are not logged in", fg=typer.colors.RED))
7176
return

src/commands/profile.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
from rich.live import Live
2-
from rich.spinner import Spinner
3-
4-
from ..lib.profile_ui import display_user_stats
5-
from ..server.api import fetch_user_profile
6-
7-
81
def profile():
92
"""List all available LeetCode problems."""
3+
from rich.live import Live
4+
from rich.spinner import Spinner
5+
6+
from ..lib.profile_ui import display_user_stats
7+
from ..server.api import fetch_user_profile
8+
109
spinner = Spinner("dots")
1110
with Live(spinner, refresh_per_second=10, transient=True) as live:
1211
live.console.print("[cyan]Fetching user profile...")

src/commands/show.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
import os
22

33
import typer
4-
from rich.progress import Progress, SpinnerColumn, TextColumn
5-
6-
from ..lib.problem_ui import ProblemDetails
7-
from ..server.auth import Auth
8-
from ..server.solution_manager import SolutionManager
9-
10-
auth_manager = Auth()
11-
solution_manager = SolutionManager(auth_manager.get_session())
124

135

146
def show(
@@ -29,6 +21,15 @@ def show(
2921
Use --compact for a condensed view or --save to export to a file.
3022
"""
3123

24+
from rich.progress import Progress, SpinnerColumn, TextColumn
25+
26+
from ..lib.problem_ui import ProblemDetails
27+
from ..server.auth import Auth
28+
from ..server.solution_manager import SolutionManager
29+
30+
auth_manager = Auth()
31+
solution_manager = SolutionManager(auth_manager.get_session())
32+
3233
if not auth_manager.is_authenticated:
3334
typer.echo(
3435
typer.style(

src/commands/solution.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
11
import typer
2-
from rich.progress import Progress, SpinnerColumn, TextColumn
3-
4-
from src.lib.solution_ui import SolutionUI
5-
6-
from ..server.auth import Auth
7-
from ..server.solution_manager import SolutionManager
8-
9-
auth = Auth()
10-
solution_manager = SolutionManager(auth.get_session())
112

123

134
def solutions(
@@ -20,6 +11,16 @@ def solutions(
2011
):
2112
"""Fetch solution for a problem"""
2213

14+
from rich.progress import Progress, SpinnerColumn, TextColumn
15+
16+
from src.lib.solution_ui import SolutionUI
17+
18+
from ..server.auth import Auth
19+
from ..server.solution_manager import SolutionManager
20+
21+
auth = Auth()
22+
solution_manager = SolutionManager(auth.get_session())
23+
2324
try:
2425
with Progress(
2526
SpinnerColumn(),

src/commands/submit.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,6 @@
44

55
import typer
66

7-
from ..lib.submission_ui import (
8-
create_submission_progress,
9-
display_auth_error,
10-
display_exception_error,
11-
display_file_not_found_error,
12-
display_language_detection_error,
13-
display_language_detection_message,
14-
display_problem_not_found_error,
15-
display_submission_canceled,
16-
display_submission_details,
17-
display_submission_results,
18-
)
19-
from ..server.auth import Auth
20-
from ..server.config import LANGUAGE_MAP
21-
from ..server.solution_manager import SolutionManager
22-
23-
auth_manager = Auth()
24-
solution_manager = SolutionManager(auth_manager.get_session())
25-
267

278
def submit(
289
problem: str = typer.Argument(
@@ -40,6 +21,26 @@ def submit(
4021
Uploads your solution file to LeetCode and returns the verdict.
4122
Language is auto-detected from file extension if not specified.
4223
"""
24+
25+
from ..lib.submission_ui import (
26+
create_submission_progress,
27+
display_auth_error,
28+
display_exception_error,
29+
display_file_not_found_error,
30+
display_language_detection_error,
31+
display_language_detection_message,
32+
display_problem_not_found_error,
33+
display_submission_canceled,
34+
display_submission_details,
35+
display_submission_results,
36+
)
37+
from ..server.auth import Auth
38+
from ..server.config import LANGUAGE_MAP
39+
from ..server.solution_manager import SolutionManager
40+
41+
auth_manager = Auth()
42+
solution_manager = SolutionManager(auth_manager.get_session())
43+
4344
if not auth_manager.is_authenticated:
4445
display_auth_error()
4546

src/commands/test.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,32 @@
22

33
import typer
44

5-
from ..lib.submission_ui import (
6-
create_submission_progress,
7-
display_auth_error,
8-
display_exception_error,
9-
display_file_not_found_error,
10-
display_language_detection_error,
11-
display_language_detection_message,
12-
display_submission_results,
13-
)
14-
from ..server.auth import Auth
15-
from ..server.config import LANGUAGE_MAP
16-
from ..server.solution_manager import SolutionManager
17-
18-
auth_manager = Auth()
19-
solution_manager = SolutionManager(auth_manager.get_session())
20-
21-
FILE_EXT_TO_LANG = {ext.lstrip("."): lang for ext, lang in LANGUAGE_MAP.items()}
5+
from src.server.config import LANGUAGE_MAP
226

237

248
def test(
259
problem: str = typer.Argument(..., help="Problem slug (e.g., 'two-sum')"),
2610
file: Path = typer.Argument(..., help="Path to solution file"),
2711
):
2812
"""Test a solution with LeetCode's test cases"""
13+
14+
from ..lib.submission_ui import (
15+
create_submission_progress,
16+
display_auth_error,
17+
display_exception_error,
18+
display_file_not_found_error,
19+
display_language_detection_error,
20+
display_language_detection_message,
21+
display_submission_results,
22+
)
23+
from ..server.auth import Auth
24+
from ..server.solution_manager import SolutionManager
25+
26+
auth_manager = Auth()
27+
solution_manager = SolutionManager(auth_manager.get_session())
28+
29+
FILE_EXT_TO_LANG = {ext.lstrip("."): lang for ext, lang in LANGUAGE_MAP.items()}
30+
2931
if not auth_manager.is_authenticated:
3032
display_auth_error()
3133

0 commit comments

Comments
 (0)