Skip to content

Commit c9f5eea

Browse files
CopilotMte90
andcommitted
Add chunk_index validation and clean up SQL statement
Co-authored-by: Mte90 <403283+Mte90@users.noreply.github.com>
1 parent 7102510 commit c9f5eea

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

ai/analyzer.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,12 @@ def _get_chunk_text(database_path: str, file_id: int, chunk_index: int) -> Optio
327327
# Extract the chunk
328328
if CHUNK_SIZE <= 0:
329329
return content
330+
331+
# Validate chunk_index
332+
if chunk_index < 0:
333+
logger.warning(f"Invalid chunk_index {chunk_index} for file_id={file_id}")
334+
return None
335+
330336
step = max(1, CHUNK_SIZE - CHUNK_OVERLAP)
331337
start = chunk_index * step
332338
end = min(start + CHUNK_SIZE, len(content))

db/operations.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,14 +234,14 @@ def store_file(database_path, path, content, language, last_modified=None, file_
234234
sqlite 'database is locked' errors in multithreaded scenarios.
235235
Supports incremental indexing with last_modified and file_hash tracking.
236236
Note: Does not store full file content in database (only snippet), content is read from filesystem when needed.
237+
The content parameter is still required to generate the snippet.
237238
Returns lastrowid (same as the previous store_file implementation).
238239
"""
239240
snippet = (content[:512] if content else "")
240241
sql = """
241-
INSERT INTO files (path, content, language, snippet, last_modified, file_hash, updated_at)
242-
VALUES (?, NULL, ?, ?, ?, ?, datetime('now'))
242+
INSERT INTO files (path, language, snippet, last_modified, file_hash, updated_at)
243+
VALUES (?, ?, ?, ?, ?, datetime('now'))
243244
ON CONFLICT(path) DO UPDATE SET
244-
content=NULL,
245245
language=excluded.language,
246246
snippet=excluded.snippet,
247247
last_modified=excluded.last_modified,

0 commit comments

Comments
 (0)