Feat: Improve 'user_canvan_version' delete and 'document' delete performance (#6553)

### What problem does this PR solve?

1.  Add delete_by_ids method
2. Add get_doc_ids_by_doc_names
3. Improve user_canvan_version's logic (avoid O(n) db IO)
4. Improve document delete logic (avoid O(n) db IO)

### Type of change

- [x] Performance Improvement
This commit is contained in:
Stephen Hu
2025-05-07 10:55:08 +08:00
committed by GitHub
parent 539876af11
commit 27ffc0ed74
4 changed files with 33 additions and 4 deletions

View File

@ -360,6 +360,15 @@ class DocumentService(CommonService):
if not doc_id:
return
return doc_id[0]["id"]
@classmethod
@DB.connection_context()
def get_doc_ids_by_doc_names(cls, doc_names):
if not doc_names:
return []
query = cls.model.select(cls.model.id).where(cls.model.name.in_(doc_names))
return list(query.scalars().iterator())
@classmethod
@DB.connection_context()