fix(scripts): chunk Phase C deletes to dodge SQLite param cap
DELETE ... WHERE itemID IN (?,?,...) with 33k+ host parameters trips SQLITE_LIMIT_VARIABLE_NUMBER (default 32766 on modern builds, 999 on older). Batch by 500 so the cleanup runs to completion regardless of build limits. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -196,14 +196,19 @@ def phase_c_cleanup() -> dict[str, int]:
|
||||
item_ids_to_delete.append(item_id)
|
||||
|
||||
if item_ids_to_delete:
|
||||
placeholders = ",".join("?" * len(item_ids_to_delete))
|
||||
# SQLite caps host parameters per statement (default 32766 on 3.32+,
|
||||
# 999 on older builds). 33k+ IDs at once trips it — chunk to be safe.
|
||||
BATCH = 500
|
||||
for i in range(0, len(item_ids_to_delete), BATCH):
|
||||
chunk = item_ids_to_delete[i : i + BATCH]
|
||||
placeholders = ",".join("?" * len(chunk))
|
||||
zot_con.execute(
|
||||
f"DELETE FROM itemAttachments WHERE itemID IN ({placeholders})",
|
||||
item_ids_to_delete,
|
||||
chunk,
|
||||
)
|
||||
zot_con.execute(
|
||||
f"DELETE FROM items WHERE itemID IN ({placeholders})",
|
||||
item_ids_to_delete,
|
||||
chunk,
|
||||
)
|
||||
stats["zot_rows_deleted"] = len(item_ids_to_delete)
|
||||
zot_con.commit()
|
||||
|
||||
Reference in New Issue
Block a user