KevinHuSh
commited on
Commit
·
036238f
1
Parent(s):
8e8680b
fix doc number miss-match issue (#822)
Browse files### What problem does this PR solve?
#620
### Type of change
- [x] Bug Fix (non-breaking change which fixes an issue)
- api/apps/document_app.py +1 -5
- api/apps/file2document_app.py +2 -10
- api/apps/file_app.py +1 -5
- api/apps/kb_app.py +1 -6
- api/db/services/document_service.py +2 -17
api/apps/document_app.py
CHANGED
|
@@ -250,13 +250,9 @@ def rm():
|
|
| 250 |
if not tenant_id:
|
| 251 |
return get_data_error_result(retmsg="Tenant not found!")
|
| 252 |
|
| 253 |
-
ELASTICSEARCH.deleteByQuery(
|
| 254 |
-
Q("match", doc_id=doc.id), idxnm=search.index_name(tenant_id))
|
| 255 |
-
|
| 256 |
-
DocumentService.clear_chunk_num(doc_id)
|
| 257 |
b, n = File2DocumentService.get_minio_address(doc_id=doc_id)
|
| 258 |
|
| 259 |
-
if not DocumentService.
|
| 260 |
return get_data_error_result(
|
| 261 |
retmsg="Database error (Document removal)!")
|
| 262 |
|
|
|
|
| 250 |
if not tenant_id:
|
| 251 |
return get_data_error_result(retmsg="Tenant not found!")
|
| 252 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 253 |
b, n = File2DocumentService.get_minio_address(doc_id=doc_id)
|
| 254 |
|
| 255 |
+
if not DocumentService.remove_document(doc, tenant_id):
|
| 256 |
return get_data_error_result(
|
| 257 |
retmsg="Database error (Document removal)!")
|
| 258 |
|
api/apps/file2document_app.py
CHANGED
|
@@ -58,11 +58,7 @@ def convert():
|
|
| 58 |
tenant_id = DocumentService.get_tenant_id(doc_id)
|
| 59 |
if not tenant_id:
|
| 60 |
return get_data_error_result(retmsg="Tenant not found!")
|
| 61 |
-
|
| 62 |
-
Q("match", doc_id=doc.id), idxnm=search.index_name(tenant_id))
|
| 63 |
-
DocumentService.increment_chunk_num(
|
| 64 |
-
doc.id, doc.kb_id, doc.token_num * -1, doc.chunk_num * -1, 0)
|
| 65 |
-
if not DocumentService.delete(doc):
|
| 66 |
return get_data_error_result(
|
| 67 |
retmsg="Database error (Document removal)!")
|
| 68 |
File2DocumentService.delete_by_file_id(id)
|
|
@@ -125,11 +121,7 @@ def rm():
|
|
| 125 |
tenant_id = DocumentService.get_tenant_id(doc_id)
|
| 126 |
if not tenant_id:
|
| 127 |
return get_data_error_result(retmsg="Tenant not found!")
|
| 128 |
-
|
| 129 |
-
Q("match", doc_id=doc.id), idxnm=search.index_name(tenant_id))
|
| 130 |
-
DocumentService.increment_chunk_num(
|
| 131 |
-
doc.id, doc.kb_id, doc.token_num * -1, doc.chunk_num * -1, 0)
|
| 132 |
-
if not DocumentService.delete(doc):
|
| 133 |
return get_data_error_result(
|
| 134 |
retmsg="Database error (Document removal)!")
|
| 135 |
return get_json_result(data=True)
|
|
|
|
| 58 |
tenant_id = DocumentService.get_tenant_id(doc_id)
|
| 59 |
if not tenant_id:
|
| 60 |
return get_data_error_result(retmsg="Tenant not found!")
|
| 61 |
+
if not DocumentService.remove_document(doc, tenant_id):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
return get_data_error_result(
|
| 63 |
retmsg="Database error (Document removal)!")
|
| 64 |
File2DocumentService.delete_by_file_id(id)
|
|
|
|
| 121 |
tenant_id = DocumentService.get_tenant_id(doc_id)
|
| 122 |
if not tenant_id:
|
| 123 |
return get_data_error_result(retmsg="Tenant not found!")
|
| 124 |
+
if not DocumentService.remove_document(doc, tenant_id):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
return get_data_error_result(
|
| 126 |
retmsg="Database error (Document removal)!")
|
| 127 |
return get_json_result(data=True)
|
api/apps/file_app.py
CHANGED
|
@@ -277,11 +277,7 @@ def rm():
|
|
| 277 |
tenant_id = DocumentService.get_tenant_id(doc_id)
|
| 278 |
if not tenant_id:
|
| 279 |
return get_data_error_result(retmsg="Tenant not found!")
|
| 280 |
-
|
| 281 |
-
Q("match", doc_id=doc.id), idxnm=search.index_name(tenant_id))
|
| 282 |
-
DocumentService.increment_chunk_num(
|
| 283 |
-
doc.id, doc.kb_id, doc.token_num * -1, doc.chunk_num * -1, 0)
|
| 284 |
-
if not DocumentService.delete(doc):
|
| 285 |
return get_data_error_result(
|
| 286 |
retmsg="Database error (Document removal)!")
|
| 287 |
File2DocumentService.delete_by_file_id(file_id)
|
|
|
|
| 277 |
tenant_id = DocumentService.get_tenant_id(doc_id)
|
| 278 |
if not tenant_id:
|
| 279 |
return get_data_error_result(retmsg="Tenant not found!")
|
| 280 |
+
if not DocumentService.remove_document(doc, tenant_id):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 281 |
return get_data_error_result(
|
| 282 |
retmsg="Database error (Document removal)!")
|
| 283 |
File2DocumentService.delete_by_file_id(file_id)
|
api/apps/kb_app.py
CHANGED
|
@@ -136,12 +136,7 @@ def rm():
|
|
| 136 |
data=False, retmsg=f'Only owner of knowledgebase authorized for this operation.', retcode=RetCode.OPERATING_ERROR)
|
| 137 |
|
| 138 |
for doc in DocumentService.query(kb_id=req["kb_id"]):
|
| 139 |
-
|
| 140 |
-
Q("match", doc_id=doc.id), idxnm=search.index_name(kbs[0].tenant_id))
|
| 141 |
-
|
| 142 |
-
DocumentService.increment_chunk_num(
|
| 143 |
-
doc.id, doc.kb_id, doc.token_num * -1, doc.chunk_num * -1, 0)
|
| 144 |
-
if not DocumentService.delete(doc):
|
| 145 |
return get_data_error_result(
|
| 146 |
retmsg="Database error (Document removal)!")
|
| 147 |
|
|
|
|
| 136 |
data=False, retmsg=f'Only owner of knowledgebase authorized for this operation.', retcode=RetCode.OPERATING_ERROR)
|
| 137 |
|
| 138 |
for doc in DocumentService.query(kb_id=req["kb_id"]):
|
| 139 |
+
if not DocumentService.remove_document(doc, kbs[0].tenant_id):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
return get_data_error_result(
|
| 141 |
retmsg="Database error (Document removal)!")
|
| 142 |
|
api/db/services/document_service.py
CHANGED
|
@@ -70,27 +70,12 @@ class DocumentService(CommonService):
|
|
| 70 |
raise RuntimeError("Database error (Knowledgebase)!")
|
| 71 |
return doc
|
| 72 |
|
| 73 |
-
@classmethod
|
| 74 |
-
@DB.connection_context()
|
| 75 |
-
def delete(cls, doc):
|
| 76 |
-
e, kb = KnowledgebaseService.get_by_id(doc.kb_id)
|
| 77 |
-
if not KnowledgebaseService.update_by_id(
|
| 78 |
-
kb.id, {"doc_num": max(0, kb.doc_num - 1)}):
|
| 79 |
-
raise RuntimeError("Database error (Knowledgebase)!")
|
| 80 |
-
return cls.delete_by_id(doc.id)
|
| 81 |
-
|
| 82 |
@classmethod
|
| 83 |
@DB.connection_context()
|
| 84 |
def remove_document(cls, doc, tenant_id):
|
| 85 |
ELASTICSEARCH.deleteByQuery(
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
cls.increment_chunk_num(
|
| 89 |
-
doc.id, doc.kb_id, doc.token_num * -1, doc.chunk_num * -1, 0)
|
| 90 |
-
if not cls.delete(doc):
|
| 91 |
-
raise RuntimeError("Database error (Document removal)!")
|
| 92 |
-
|
| 93 |
-
MINIO.rm(doc.kb_id, doc.location)
|
| 94 |
return cls.delete_by_id(doc.id)
|
| 95 |
|
| 96 |
@classmethod
|
|
|
|
| 70 |
raise RuntimeError("Database error (Knowledgebase)!")
|
| 71 |
return doc
|
| 72 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
@classmethod
|
| 74 |
@DB.connection_context()
|
| 75 |
def remove_document(cls, doc, tenant_id):
|
| 76 |
ELASTICSEARCH.deleteByQuery(
|
| 77 |
+
Q("match", doc_id=doc.id), idxnm=search.index_name(tenant_id))
|
| 78 |
+
cls.clear_chunk_num(doc.id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
return cls.delete_by_id(doc.id)
|
| 80 |
|
| 81 |
@classmethod
|