diff --git a/mempalace/miner.py b/mempalace/miner.py index 56b767f..d80a533 100644 --- a/mempalace/miner.py +++ b/mempalace/miner.py @@ -847,18 +847,24 @@ def status(palace_path: str): print(" Run: mempalace init then mempalace mine ") return - # Count by wing and room + # Count by wing and room — paginate to avoid SQLite "too many SQL + # variables" error on large palaces (see #802, #850). total = col.count() - r = col.get(limit=total, include=["metadatas"]) if total else {"metadatas": []} - metas = r["metadatas"] - - wing_rooms = defaultdict(lambda: defaultdict(int)) - for m in metas: - m = m or {} - wing_rooms[m.get("wing", "?")][m.get("room", "?")] += 1 + wing_rooms: dict = defaultdict(lambda: defaultdict(int)) + batch_size = 5000 + offset = 0 + while offset < total: + r = col.get(limit=batch_size, offset=offset, include=["metadatas"]) + batch = r["metadatas"] + if not batch: + break + for m in batch: + m = m or {} + wing_rooms[m.get("wing", "?")][m.get("room", "?")] += 1 + offset += len(batch) print(f"\n{'=' * 55}") - print(f" MemPalace Status — {len(metas)} drawers") + print(f" MemPalace Status — {total} drawers") print(f"{'=' * 55}\n") for wing, rooms in sorted(wing_rooms.items()): print(f" WING: {wing}")