Skip to content

Commit 85cc283

Browse files
fix: move stdlib json import to module level in hot-path functions
Hoists `import json` from inside hot-path function bodies to module top in two services, matching the pattern from #1216 (which fixed #1209 for `copy` and `datetime` in app/nodes/). - app/services/tracer_client/tracer_integrations.py - get_all_integrations: import was inside a `for` loop iterating integration records, re-running the import statement once per iteration - get_grafana_credentials: import was per-call during integration resolution - app/services/lambda_client.py - invoke_function: import was per Lambda invocation Fixes #1242
1 parent ae53af1 commit 85cc283

2 files changed

Lines changed: 2 additions & 6 deletions

File tree

app/services/lambda_client.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Lambda client for function inspection and log retrieval."""
22

33
import base64
4+
import json
45
from contextlib import suppress
56
from io import BytesIO
67
from typing import Any
@@ -325,8 +326,6 @@ def invoke_function(
325326
if credentials_error:
326327
return credentials_error
327328

328-
import json
329-
330329
try:
331330
kwargs = {
332331
"FunctionName": function_name,

app/services/tracer_client/tracer_integrations.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from __future__ import annotations
44

5+
import json
56
import logging
67
from dataclasses import dataclass
78
from typing import Any
@@ -65,8 +66,6 @@ def get_all_integrations(self) -> list[dict[str, Any]]:
6566
for integration in integrations:
6667
creds = integration.get("credentials", {})
6768
if isinstance(creds, str):
68-
import json
69-
7069
try:
7170
integration["credentials"] = json.loads(creds)
7271
except (json.JSONDecodeError, TypeError):
@@ -98,8 +97,6 @@ def get_grafana_credentials(self) -> GrafanaIntegrationCredentials:
9897

9998
credentials = integration.get("credentials", {})
10099
if isinstance(credentials, str):
101-
import json
102-
103100
try:
104101
credentials = json.loads(credentials)
105102
except (json.JSONDecodeError, TypeError):

0 commit comments

Comments
 (0)