From 6116ed917f133ff633b141b553f3ea4810656b35 Mon Sep 17 00:00:00 2001 From: Kapil Lamba Date: Sun, 10 May 2026 22:34:38 +0530 Subject: [PATCH] Remove dead code surfaced by find_dead_code Drop six unreferenced functions: - db.py: upsert_symbol, upsert_reference, upsert_embedding (parser.py performs writes inline through batch_insert_embeddings and direct cursor calls; these helpers had no callers) - logging_config.py: get_parser_logger, get_git_logger - validation.py: validate_path_in_directory Also fix the transaction() docstring example to reference upsert_file, which is the actual function used in parser.py:594. Verified with the find_dead_code MCP tool (0 candidates after removal) and pytest on the touched modules (59 tests pass). Co-Authored-By: Claude Opus 4.7 (1M context) --- db.py | 75 +---------------------------------------------- logging_config.py | 10 ------- validation.py | 33 --------------------- 3 files changed, 1 insertion(+), 117 deletions(-) diff --git a/db.py b/db.py index 012bcee..bdac297 100644 --- a/db.py +++ b/db.py @@ -349,7 +349,7 @@ def transaction(db: sqlite3.Connection): Example: with transaction(db): for item in items: - upsert_symbol(db, ..., auto_commit=False) + upsert_file(db, ..., auto_commit=False) # Single commit here """ # Disable autocommit by starting a transaction @@ -672,79 +672,6 @@ def delete_file_data(db: sqlite3.Connection, file_id: int, auto_commit: bool = T db.commit() -def upsert_symbol( - db: sqlite3.Connection, - name: str, - kind: str, - file_id: int, - line_start: int, - line_end: int, - parent_symbol_id: int | None, - source_text: str, - auto_commit: bool = True, -) -> int: - """Insert or update a symbol record. Returns the symbol_id.""" - db.execute( - """ - INSERT INTO symbols (name, kind, file_id, line_start, line_end, - parent_symbol_id, source_text) - VALUES (?, ?, ?, ?, ?, ?, ?) - ON CONFLICT(file_id, name, kind, line_start) DO UPDATE SET - line_end = excluded.line_end, - parent_symbol_id = excluded.parent_symbol_id, - source_text = excluded.source_text - """, - (name, kind, file_id, line_start, line_end, parent_symbol_id, source_text), - ) - if auto_commit: - db.commit() - row = db.execute( - "SELECT id FROM symbols WHERE file_id = ? AND name = ? AND kind = ? AND line_start = ?", - (file_id, name, kind, line_start), - ).fetchone() - return row[0] - - -def upsert_reference( - db: sqlite3.Connection, - symbol_name: str, - file_id: int, - line_number: int, - auto_commit: bool = True, -) -> None: - """Insert or update a cross-reference record.""" - db.execute( - """ - INSERT INTO references_ (symbol_name, file_id, line_number) - VALUES (?, ?, ?) - ON CONFLICT(symbol_name, file_id, line_number) DO NOTHING - """, - (symbol_name, file_id, line_number), - ) - if auto_commit: - db.commit() - - -def upsert_embedding( - db: sqlite3.Connection, - symbol_id: int, - embedding: list[float], - auto_commit: bool = True, -) -> None: - """Insert or replace a symbol's dense vector embedding.""" - import struct - - blob = struct.pack(f"{len(embedding)}f", *embedding) - # sqlite-vec doesn't support ON CONFLICT, so delete-then-insert - db.execute("DELETE FROM symbol_embeddings WHERE symbol_id = ?", (symbol_id,)) - db.execute( - "INSERT INTO symbol_embeddings (symbol_id, embedding) VALUES (?, ?)", - (symbol_id, blob), - ) - if auto_commit: - db.commit() - - def batch_insert_embeddings( db: sqlite3.Connection, pairs: list[tuple[int, list[float]]], diff --git a/logging_config.py b/logging_config.py index 2b5fbd4..d0953bf 100644 --- a/logging_config.py +++ b/logging_config.py @@ -199,16 +199,6 @@ def get_db_logger() -> logging.Logger: return get_logger("db") -def get_parser_logger() -> logging.Logger: - """Get logger for parser module.""" - return get_logger("parser") - - def get_query_logger() -> logging.Logger: """Get logger for query module.""" return get_logger("queries") - - -def get_git_logger() -> logging.Logger: - """Get logger for git search module.""" - return get_logger("git") diff --git a/validation.py b/validation.py index 0fb3a8f..1580db5 100644 --- a/validation.py +++ b/validation.py @@ -232,39 +232,6 @@ def validate_top_k(value: int, min_val: int = 1, max_val: int = 100, default: in return value -def validate_path_in_directory(path: str, base_dir: str) -> Path: - """Validate that a path is within a base directory (prevent path traversal). - - Args: - path: Path to validate - base_dir: Base directory that path must be within - - Returns: - Resolved Path object - - Raises: - ValidationError: If path escapes base directory - """ - if not path: - raise ValidationError("Path cannot be empty") - - try: - resolved_path = Path(path).resolve() - resolved_base = Path(base_dir).resolve() - except Exception as e: - raise ValidationError(f"Invalid path: {path}", {"exception": str(e)}) - - try: - resolved_path.relative_to(resolved_base) - except ValueError: - raise ValidationError( - f"Path escapes base directory: {path}", - {"base_directory": str(resolved_base)} - ) - - return resolved_path - - def sanitize_fts_query(query: str) -> str: """Sanitize a query for FTS5 MATCH with good recall.