diff --git a/proxy.py b/proxy.py index f5dfad8..6aeb5f4 100644 --- a/proxy.py +++ b/proxy.py @@ -599,8 +599,8 @@ async def lm_remote_proxy_middleware(request: web.Request, handler): body = json.loads(response.body) enriched = _enrich_list_response(body) return web.json_response(enriched) - except Exception: - pass # Return original response on any error + except Exception as exc: + logger.debug("[LM-Remote] Stats enrichment failed: %s", exc) # Inject stats UI script into HTML pages if (path in _PROXY_PAGE_ROUTES or path.rstrip("/") in _PROXY_PAGE_ROUTES): if response.status == 200: @@ -616,8 +616,8 @@ async def lm_remote_proxy_middleware(request: web.Request, handler): charset="utf-8", status=response.status, ) - except Exception: - pass + except Exception as exc: + logger.debug("[LM-Remote] HTML injection failed: %s", exc) return response # Not a LoRA Manager route — fall through diff --git a/stats_db.py b/stats_db.py index 1f2d66a..6060295 100644 --- a/stats_db.py +++ b/stats_db.py @@ -32,7 +32,7 @@ class StatsDB: def init(self) -> None: """Create the database and table if they don't exist.""" - self._conn = sqlite3.connect(str(self._db_path)) + self._conn = sqlite3.connect(str(self._db_path), check_same_thread=False) self._conn.row_factory = sqlite3.Row self._conn.execute("PRAGMA journal_mode=WAL") self._conn.executescript(_SCHEMA) diff --git a/stats_service.py b/stats_service.py index e431d25..0c43e3f 100644 --- a/stats_service.py +++ b/stats_service.py @@ -72,25 +72,28 @@ class StatsFetchService: ) return self._session - async def _fetch_model(self, model_id: int) -> dict | None: + async def _fetch_model(self, model_id: int, _retries: int = 2) -> dict | None: """Fetch a single model's data from CivitAI API.""" url = f"{_CIVITAI_API}/models/{model_id}" session = await self._get_session() - try: - async with session.get(url) as resp: - if resp.status == 429: - logger.warning("[LM-Remote] CivitAI rate limited, backing off") - await asyncio.sleep(5) - return None - if resp.status != 200: - logger.debug("[LM-Remote] CivitAI returned %d for model %d", - resp.status, model_id) - return None - return await resp.json() - except Exception as exc: - logger.warning("[LM-Remote] CivitAI fetch failed for model %d: %s", - model_id, exc) - return None + for attempt in range(_retries + 1): + try: + async with session.get(url) as resp: + if resp.status == 429: + logger.warning("[LM-Remote] CivitAI rate limited, backing off (attempt %d)", + attempt + 1) + await asyncio.sleep(5 * (attempt + 1)) + continue + if resp.status != 200: + logger.debug("[LM-Remote] CivitAI returned %d for model %d", + resp.status, model_id) + return None + return await resp.json() + except Exception as exc: + logger.warning("[LM-Remote] CivitAI fetch failed for model %d: %s", + model_id, exc) + return None + return None async def fetch_stats_for_models( self,