mirror of
https://github.com/VectifyAI/PageIndex.git
synced 2026-07-24 21:41:04 +02:00
fix: delete the DB row before files so an interrupted delete can't leave a broken document
Files-first meant a failed DB delete left a valid-looking row whose files were gone: still listed, status completed, dangling file_path, and the surviving file_hash made re-adds dedup onto the broken doc. Row first degrades the same failure to harmless orphan files — the order delete_collection already uses.
This commit is contained in:
parent
9fc7b680e2
commit
a11493502f
1 changed files with 3 additions and 1 deletions
|
|
@ -245,13 +245,15 @@ class LocalBackend:
|
|||
|
||||
def delete_document(self, collection: str, doc_id: str) -> None:
|
||||
doc = self._require_document(collection, doc_id)
|
||||
# DB row first: an interrupted delete then leaves harmless orphan
|
||||
# files, not a valid-looking document whose files are gone.
|
||||
self._storage.delete_document(collection, doc_id)
|
||||
if doc.get("file_path"):
|
||||
Path(doc["file_path"]).unlink(missing_ok=True)
|
||||
# Clean up images directory: files/{collection}/{doc_id}/
|
||||
doc_dir = self._files_dir / collection / doc_id
|
||||
if doc_dir.exists():
|
||||
shutil.rmtree(doc_dir)
|
||||
self._storage.delete_document(collection, doc_id)
|
||||
|
||||
def get_agent_tools(self, collection: str, doc_ids: list[str] | None = None) -> AgentTools:
|
||||
"""Build agent tools.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue