Skip to content

Commit a6874c4

Browse files
committed
perf(core): skip checksums when the project index is empty
Signed-off-by: phernandez <paul@basicmachines.co>
1 parent 368e607 commit a6874c4

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

src/basic_memory/index/local_project.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,12 @@ async def list_observed_index_files(self) -> tuple[RuntimeObservedIndexFile, ...
317317
if self.indexed_stat_source is not None
318318
else {}
319319
)
320+
# With a confirmed empty index, every discovered path is new. Hashes
321+
# cannot identify changes or moves yet; the batch reader computes them
322+
# when indexing content. Status can therefore count files without reads.
323+
if self.indexed_stat_source is not None and not indexed_stats:
324+
return tuple(RuntimeObservedIndexFile(path=path) for path in file_paths)
325+
320326
observed_files: list[RuntimeObservedIndexFile] = []
321327
for file_path in file_paths:
322328
try:

test-int/cli/test_status_wait_integration.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,34 @@ def test_status_wait_returns_once_indexed(app, app_config, test_project, config_
3535
data = json.loads(result.output[start:])
3636
assert data["total_files"] == 1
3737
assert data["observed_files"][0]["path"] == "test-notes/Wait Test Note.md"
38+
39+
40+
def test_unindexed_status_counts_files_without_hashing(
41+
app, app_config, test_project, config_manager, monkeypatch
42+
) -> None:
43+
"""First status walks eligible paths without reading their contents."""
44+
from pathlib import Path
45+
46+
from basic_memory.services import FileService
47+
48+
root = Path(test_project.path)
49+
(root / "notes").mkdir()
50+
(root / "notes" / "new.md").write_text("# New\n", encoding="utf-8")
51+
(root / "asset.txt").write_text("unindexed asset", encoding="utf-8")
52+
(root / ".hidden.md").write_text("hidden", encoding="utf-8")
53+
54+
async def unexpected_checksum(self: FileService, path: str) -> str:
55+
raise AssertionError(f"Unindexed status must not hash {path}")
56+
57+
monkeypatch.setattr(FileService, "compute_checksum", unexpected_checksum)
58+
result = runner.invoke(cli_app, ["status", "--json"])
59+
60+
assert result.exit_code == 0, result.output
61+
data = json.loads(result.stdout)
62+
assert data["total_files"] == 2
63+
assert {item["path"] for item in data["observed_files"]} == {"notes/new.md", "asset.txt"}
64+
assert all(item["checksum"] is None for item in data["observed_files"])
65+
assert data["readiness"]["phase"] == "never_indexed"
66+
assert data["readiness"]["indexed_entities"] == 0
67+
files = next(stage for stage in data["readiness"]["stages"] if stage["name"] == "files")
68+
assert files["pending"] == files["total"] == 2

0 commit comments

Comments
 (0)