Remove dead code (#3210)
Browse files### What problem does this PR solve?
Remove dead code
### Type of change
- [x] Refactoring
api/db/services/document_service.py
CHANGED
|
@@ -95,35 +95,6 @@ class DocumentService(CommonService):
|
|
| 95 |
|
| 96 |
return list(docs.dicts()), count
|
| 97 |
|
| 98 |
-
@classmethod
|
| 99 |
-
@DB.connection_context()
|
| 100 |
-
def list_documents_in_dataset(cls, dataset_id, offset, count, order_by, descend, keywords):
|
| 101 |
-
if keywords:
|
| 102 |
-
docs = cls.model.select().where(
|
| 103 |
-
(cls.model.kb_id == dataset_id),
|
| 104 |
-
(fn.LOWER(cls.model.name).contains(keywords.lower()))
|
| 105 |
-
)
|
| 106 |
-
else:
|
| 107 |
-
docs = cls.model.select().where(cls.model.kb_id == dataset_id)
|
| 108 |
-
|
| 109 |
-
total = docs.count()
|
| 110 |
-
|
| 111 |
-
if descend == 'True':
|
| 112 |
-
docs = docs.order_by(cls.model.getter_by(order_by).desc())
|
| 113 |
-
if descend == 'False':
|
| 114 |
-
docs = docs.order_by(cls.model.getter_by(order_by).asc())
|
| 115 |
-
|
| 116 |
-
docs = list(docs.dicts())
|
| 117 |
-
docs_length = len(docs)
|
| 118 |
-
|
| 119 |
-
if offset < 0 or offset > docs_length:
|
| 120 |
-
raise IndexError("Offset is out of the valid range.")
|
| 121 |
-
|
| 122 |
-
if count == -1:
|
| 123 |
-
return docs[offset:], total
|
| 124 |
-
|
| 125 |
-
return docs[offset:offset + count], total
|
| 126 |
-
|
| 127 |
@classmethod
|
| 128 |
@DB.connection_context()
|
| 129 |
def insert(cls, doc):
|
|
@@ -426,7 +397,7 @@ class DocumentService(CommonService):
|
|
| 426 |
try:
|
| 427 |
_, doc = DocumentService.get_by_id(doc_id)
|
| 428 |
return doc.run == TaskStatus.CANCEL.value or doc.progress < 0
|
| 429 |
-
except Exception
|
| 430 |
pass
|
| 431 |
return False
|
| 432 |
|
|
|
|
| 95 |
|
| 96 |
return list(docs.dicts()), count
|
| 97 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
@classmethod
|
| 99 |
@DB.connection_context()
|
| 100 |
def insert(cls, doc):
|
|
|
|
| 397 |
try:
|
| 398 |
_, doc = DocumentService.get_by_id(doc_id)
|
| 399 |
return doc.run == TaskStatus.CANCEL.value or doc.progress < 0
|
| 400 |
+
except Exception:
|
| 401 |
pass
|
| 402 |
return False
|
| 403 |
|
api/db/services/knowledgebase_service.py
CHANGED
|
@@ -66,31 +66,6 @@ class KnowledgebaseService(CommonService):
|
|
| 66 |
|
| 67 |
return list(kbs.dicts())
|
| 68 |
|
| 69 |
-
@classmethod
|
| 70 |
-
@DB.connection_context()
|
| 71 |
-
def get_by_tenant_ids_by_offset(cls, joined_tenant_ids, user_id, offset, count, orderby, desc):
|
| 72 |
-
kbs = cls.model.select().where(
|
| 73 |
-
((cls.model.tenant_id.in_(joined_tenant_ids) & (cls.model.permission ==
|
| 74 |
-
TenantPermission.TEAM.value)) | (
|
| 75 |
-
cls.model.tenant_id == user_id))
|
| 76 |
-
& (cls.model.status == StatusEnum.VALID.value)
|
| 77 |
-
)
|
| 78 |
-
if desc:
|
| 79 |
-
kbs = kbs.order_by(cls.model.getter_by(orderby).desc())
|
| 80 |
-
else:
|
| 81 |
-
kbs = kbs.order_by(cls.model.getter_by(orderby).asc())
|
| 82 |
-
|
| 83 |
-
kbs = list(kbs.dicts())
|
| 84 |
-
|
| 85 |
-
kbs_length = len(kbs)
|
| 86 |
-
if offset < 0 or offset > kbs_length:
|
| 87 |
-
raise IndexError("Offset is out of the valid range.")
|
| 88 |
-
|
| 89 |
-
if count == -1:
|
| 90 |
-
return kbs[offset:]
|
| 91 |
-
|
| 92 |
-
return kbs[offset:offset + count]
|
| 93 |
-
|
| 94 |
@classmethod
|
| 95 |
@DB.connection_context()
|
| 96 |
def get_detail(cls, kb_id):
|
|
|
|
| 66 |
|
| 67 |
return list(kbs.dicts())
|
| 68 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
@classmethod
|
| 70 |
@DB.connection_context()
|
| 71 |
def get_detail(cls, kb_id):
|