From d6f4db34ff863d1202ce18349981b5c6a475df8f Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Thu, 4 Jun 2026 20:22:47 +0000 Subject: [PATCH] navi-offroute: drop unused connection cache from HPAManifest (cleanup) The connection cache field (_conns) and get_connection() method were shipped in PR #53 "ready for future use" but never consumed by the v1 dispatch path: astar_hpa_multimode opens its own sqlite connection per call (astar.py:752) and changing that signature was out of scope. Per self-review of PR #53: shipping dead code in a PR is wrong even when the rationale is "future PRs will use it." Removing it here keeps the manifest module focused on lookup; whoever needs the cache later can add it alongside the use site. - Drop _conns field, get_connection() method. - Drop sqlite3 + Dict imports (no longer referenced). - Drop test_get_connection_caches_per_path. 23 deletions, 2 insertions. No production behaviour change. Co-Authored-By: Claude Opus 4.7 (1M context) --- backend/services/navi_offroute/hpa_manifest.py | 18 ++---------------- .../navi_offroute/tests/test_hpa_manifest.py | 9 --------- 2 files changed, 2 insertions(+), 25 deletions(-) diff --git a/backend/services/navi_offroute/hpa_manifest.py b/backend/services/navi_offroute/hpa_manifest.py index 19d732a..48d794c 100644 --- a/backend/services/navi_offroute/hpa_manifest.py +++ b/backend/services/navi_offroute/hpa_manifest.py @@ -10,9 +10,8 @@ neither env var set -> HPA disabled (same as today). import json import logging import os -import sqlite3 from dataclasses import dataclass, field -from typing import Dict, List, Optional +from typing import List, Optional logger = logging.getLogger(__name__) @@ -43,10 +42,8 @@ class TileDBEntry: @dataclass class HPAManifest: - """Registry of regional tile DBs + lazy per-path sqlite connection cache. - The cache is process-local mutable state; entries are immutable after load.""" + """Registry of regional tile DBs. Immutable after load.""" entries: List[TileDBEntry] = field(default_factory=list) - _conns: Dict[str, sqlite3.Connection] = field(default_factory=dict) def enabled(self) -> bool: return len(self.entries) > 0 @@ -73,17 +70,6 @@ class HPAManifest: return self.dbs_for_chunks(min(cx0, cx1), max(cx0, cx1), min(cy0, cy1), max(cy0, cy1)) - def get_connection(self, abs_path: str) -> sqlite3.Connection: - """Read-only sqlite connection cached for the life of the process. v1 - dispatch (astar_hpa_multimode) opens its own connection per call and does - not yet use this cache; multi-region UNION + admin endpoints will.""" - conn = self._conns.get(abs_path) - if conn is None: - conn = sqlite3.connect(f"file:{abs_path}?mode=ro", uri=True) - self._conns[abs_path] = conn - return conn - - # ── loaders ────────────────────────────────────────────────────────────────── def _load_from_dir(dir_path: str) -> HPAManifest: diff --git a/backend/services/navi_offroute/tests/test_hpa_manifest.py b/backend/services/navi_offroute/tests/test_hpa_manifest.py index 85d17a4..6013242 100644 --- a/backend/services/navi_offroute/tests/test_hpa_manifest.py +++ b/backend/services/navi_offroute/tests/test_hpa_manifest.py @@ -106,12 +106,3 @@ def test_load_env_disabled_paths(tmp_path, monkeypatch): # neither var set -> empty monkeypatch.delenv(hm.ENV_LEGACY, raising=False) assert not hm.load().enabled() - - -def test_get_connection_caches_per_path(tmp_path): - import sqlite3 - p = _touch(str(tmp_path), "x.db") - with sqlite3.connect(p) as c: - c.execute("CREATE TABLE t (x INTEGER)") - m = hm.HPAManifest(entries=[hm.TileDBEntry("x", p, None)]) - assert m.get_connection(p) is m.get_connection(p)