fix: add grace period to document tidy to prevent deleting new documents (#5036)
This commit is contained in:
parent
2412db1583
commit
1c1afe5dd1
2 changed files with 13 additions and 4 deletions
|
|
@ -799,7 +799,13 @@ def setup_document_routes(session_manager, upload_handler=None) -> APIRouter:
|
||||||
from src.document_actions import _JUNK_TITLES
|
from src.document_actions import _JUNK_TITLES
|
||||||
|
|
||||||
to_delete = []
|
to_delete = []
|
||||||
|
now = datetime.now(timezone.utc).replace(tzinfo=None)
|
||||||
|
|
||||||
for doc in docs:
|
for doc in docs:
|
||||||
|
# Skip freshly created documents to avoid deleting them while the user is actively editing
|
||||||
|
if doc.created_at and (now - doc.created_at).total_seconds() < 900: # 15 minutes
|
||||||
|
continue
|
||||||
|
|
||||||
content = (doc.current_content or "").strip()
|
content = (doc.current_content or "").strip()
|
||||||
title_raw = (doc.title or "").strip()
|
title_raw = (doc.title or "").strip()
|
||||||
title = title_raw.lower()
|
title = title_raw.lower()
|
||||||
|
|
@ -837,10 +843,6 @@ def setup_document_routes(session_manager, upload_handler=None) -> APIRouter:
|
||||||
to_delete.append(doc); deleted += 1; continue
|
to_delete.append(doc); deleted += 1; continue
|
||||||
if title in _JUNK_TITLES:
|
if title in _JUNK_TITLES:
|
||||||
to_delete.append(doc); deleted += 1; continue
|
to_delete.append(doc); deleted += 1; continue
|
||||||
if real_len < 30:
|
|
||||||
to_delete.append(doc); deleted += 1; continue
|
|
||||||
if "\n" not in content and real_len < 50:
|
|
||||||
to_delete.append(doc); deleted += 1; continue
|
|
||||||
|
|
||||||
# Fix empty or placeholder titles on survivors
|
# Fix empty or placeholder titles on survivors
|
||||||
if not title_raw or title_raw == "Untitled":
|
if not title_raw or title_raw == "Untitled":
|
||||||
|
|
|
||||||
|
|
@ -78,7 +78,14 @@ async def run_document_tidy(owner: str) -> str:
|
||||||
kept = 0
|
kept = 0
|
||||||
survivors = [] # docs that pass the junk rules, considered for dedup
|
survivors = [] # docs that pass the junk rules, considered for dedup
|
||||||
|
|
||||||
|
now = datetime.utcnow()
|
||||||
|
|
||||||
for doc in docs:
|
for doc in docs:
|
||||||
|
# Skip freshly created documents to avoid deleting them while the user is actively editing
|
||||||
|
if doc.created_at and (now - doc.created_at).total_seconds() < 900: # 15 minutes
|
||||||
|
survivors.append(doc)
|
||||||
|
continue
|
||||||
|
|
||||||
content = (doc.current_content or "").strip()
|
content = (doc.current_content or "").strip()
|
||||||
title = (doc.title or "").strip().lower()
|
title = (doc.title or "").strip().lower()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue