From 5078e604b4b29074d8200ca4e1d2b730de0353d8 Mon Sep 17 00:00:00 2001 From: ciregenz Date: Tue, 23 Jun 2026 22:43:48 -0700 Subject: [PATCH] [eric] analytics: trim my authored comments to one-line WHY-only; drop _locale leading-underscore --- backend/apps/service/analytics.py | 5 +---- backend/apps/service/client.py | 8 +++----- backend/apps/service/service.py | 7 ++----- backend/requirements.txt | 4 +--- 4 files changed, 7 insertions(+), 17 deletions(-) diff --git a/backend/apps/service/analytics.py b/backend/apps/service/analytics.py index e92c435f..1e938d2c 100644 --- a/backend/apps/service/analytics.py +++ b/backend/apps/service/analytics.py @@ -18,10 +18,7 @@ logger = logging.getLogger(__name__) P_CLIENT: Optional[AnalyticsClient] = None -# Where the SDK ships events. Configurable so local dev hits a local -# product-analytics-v1 (its .env BACKEND_PORT) while prod points at the -# cloud-hosted ingest via OPENSWARM_ANALYTICS_URL. NOT the desktop backend's -# port (8324); the analytics service listens on 6792. +# Env-overridable so prod points at the cloud edge; this default is the analytics service's own port, not the desktop's 8324. P_DEFAULT_ANALYTICS_URL = "http://127.0.0.1:6792" diff --git a/backend/apps/service/client.py b/backend/apps/service/client.py index c5bed0e6..bfe3f952 100644 --- a/backend/apps/service/client.py +++ b/backend/apps/service/client.py @@ -46,9 +46,7 @@ _TIMEOUT_SECONDS = 5.0 def resolve_timezone() -> str: - """Best-effort IANA timezone for analytics. Prefers the renderer-reported - value persisted in settings (the only source that works on dev / OSS where - Electron's env injection never runs), then the OS, then UTC.""" + """Settings-first (the only source that works on dev / OSS), then OS, then UTC.""" try: from backend.apps.settings.store import load_settings tz = getattr(load_settings(), "timezone", None) @@ -79,8 +77,8 @@ def resolve_locale() -> str: except Exception: pass try: - import locale as _locale - code = _locale.getlocale()[0] + import locale + code = locale.getlocale()[0] if code: return code.replace("_", "-") except Exception: diff --git a/backend/apps/service/service.py b/backend/apps/service/service.py index e5484dbf..b249dfc3 100644 --- a/backend/apps/service/service.py +++ b/backend/apps/service/service.py @@ -190,9 +190,7 @@ async def service_lifespan(): svc.sync({"identity": id_props}) - # swarm-analytics: bootstrap the client (registers + persists a token on - # first run), prove the pipe with one diagnostic log write, and link the - # user's email. All best-effort; the wrappers swallow every error. + # First-boot log write doubles as the token-registration trigger. from backend.apps.service.analytics import get_analytics_client, track_link_email analytics_client = get_analytics_client() if analytics_client is not None: @@ -251,8 +249,7 @@ async def service_lifespan(): except Exception: pass - # swarm-analytics: fire the app-closed event and flush+close the client so - # buffered events land before the process exits. Best-effort. + # Flush before the process exits or buffered events are lost. try: from backend.apps.service.analytics import track_app_closed, shutdown_analytics track_app_closed() diff --git a/backend/requirements.txt b/backend/requirements.txt index 5e6ebb43..a9b7fea0 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -16,9 +16,7 @@ python-dotenv==1.1.1 Pillow==12.2.0 httpx==0.28.1 trafilatura==2.0.0 -# swarm-analytics: typed client for the product-analytics ingest service. -# Validates payloads against the server schema locally; all calls are -# fire-and-forget and swallow errors so analytics can never break the app. +# swarm-analytics: typed client for the product-analytics ingest; fire-and-forget so it never breaks the app. swarm-analytics==0.1.1 # tzlocal: dev-mode fallback for resolving the user's IANA timezone when # Electron's OPENSWARM_TIMEZONE env var isn't set (i.e. `bash run.sh`).