Merge pull request #851 from vnguyen-lexipol/fix/status-paginate-large-palaces

Merging to fix active pagination crash — 3 users hit this on v3.3.2 in the last 20 hours (54K, 114K, 465K drawer palaces). None-guard regression fixed. 9-day production soak on 165K-drawer palace confirms stability.
This commit is contained in:
Ben Sigman
2026-04-21 17:38:04 -07:00
committed by GitHub
+13 -7
View File
@@ -847,18 +847,24 @@ def status(palace_path: str):
print(" Run: mempalace init <dir> then mempalace mine <dir>") print(" Run: mempalace init <dir> then mempalace mine <dir>")
return 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() total = col.count()
r = col.get(limit=total, include=["metadatas"]) if total else {"metadatas": []} wing_rooms: dict = defaultdict(lambda: defaultdict(int))
metas = r["metadatas"] batch_size = 5000
offset = 0
wing_rooms = defaultdict(lambda: defaultdict(int)) while offset < total:
for m in metas: r = col.get(limit=batch_size, offset=offset, include=["metadatas"])
batch = r["metadatas"]
if not batch:
break
for m in batch:
m = m or {} m = m or {}
wing_rooms[m.get("wing", "?")][m.get("room", "?")] += 1 wing_rooms[m.get("wing", "?")][m.get("room", "?")] += 1
offset += len(batch)
print(f"\n{'=' * 55}") print(f"\n{'=' * 55}")
print(f" MemPalace Status — {len(metas)} drawers") print(f" MemPalace Status — {total} drawers")
print(f"{'=' * 55}\n") print(f"{'=' * 55}\n")
for wing, rooms in sorted(wing_rooms.items()): for wing, rooms in sorted(wing_rooms.items()):
print(f" WING: {wing}") print(f" WING: {wing}")