Skip to content

Commit fb6e38e

Browse files
committed
refactor: move json import to module level in api_stream
Local `import json as _json` inside the function body was redundant — Python caches module imports, so there is no cost to importing at the top. Moving it to the module-level import block makes the dependency explicit and keeps the function body focused on its logic.
1 parent c84f1d9 commit fb6e38e

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

app.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""SOC Analyst Dashboard — Flask + psycopg2 (no ORM)."""
22
import hmac
3+
import json
34
import os
45
import queue
56
import threading
@@ -777,15 +778,13 @@ def api_stream():
777778
only works within a single worker process. For multi-worker deployments,
778779
replace with Redis pub/sub.
779780
"""
780-
import json as _json
781-
782781
def generate():
783782
q = _sse_subscribe()
784783
try:
785784
while True:
786785
try:
787786
event = q.get(timeout=30)
788-
yield f"data: {_json.dumps(event)}\n\n"
787+
yield f"data: {json.dumps(event)}\n\n"
789788
except queue.Empty:
790789
yield ": keepalive\n\n"
791790
except GeneratorExit:

0 commit comments

Comments
 (0)