|
12 | 12 | tokenization, |
13 | 13 | task_queue, |
14 | 14 | record_label_association, |
| 15 | + comments, |
15 | 16 | ) |
16 | 17 | from service.search import search |
17 | 18 | from submodules.model import enums |
|
22 | 23 | from controller.embedding import manager as embedding_manager |
23 | 24 | from controller.tokenization import tokenization_service |
24 | 25 | from util.miscellaneous_functions import chunk_list |
| 26 | +from controller.tokenization.tokenization_service import ( |
| 27 | + request_reupload_docbins, |
| 28 | +) |
| 29 | +from util import notification |
25 | 30 | import time |
26 | 31 | import traceback |
27 | 32 |
|
@@ -307,3 +312,46 @@ def __check_and_prep_edit_records( |
307 | 312 | "rla_delete_tuples": rla_delete_tuples, |
308 | 313 | "embedding_rebuilds": embedding_rebuilds, |
309 | 314 | } |
| 315 | + |
| 316 | + |
| 317 | +def delete_records( |
| 318 | + project_id: str, |
| 319 | + record_ids: List[str], |
| 320 | + as_thread: Optional[bool] = False, |
| 321 | +) -> None: |
| 322 | + if not record_ids or len(record_ids) == 0: |
| 323 | + return |
| 324 | + if as_thread: |
| 325 | + daemon.run_with_db_token( |
| 326 | + __delete_records, |
| 327 | + project_id, |
| 328 | + record_ids, |
| 329 | + ) |
| 330 | + else: |
| 331 | + __delete_records(project_id, record_ids) |
| 332 | + |
| 333 | + |
| 334 | +def __delete_records(project_id: str, record_ids: List[str]) -> None: |
| 335 | + try: |
| 336 | + row_count = record.delete_many(project_id, record_ids) |
| 337 | + if row_count == 0: |
| 338 | + print( |
| 339 | + f"No records found to delete for {record_ids} in project {project_id}", |
| 340 | + flush=True, |
| 341 | + ) |
| 342 | + return |
| 343 | + comments.delete_by_type_and_xfkey( |
| 344 | + project_id, record_ids, enums.CommentCategory.RECORD |
| 345 | + ) |
| 346 | + general.commit() |
| 347 | + |
| 348 | + request_reupload_docbins(project_id) |
| 349 | + |
| 350 | + all_embeddings = embedding.get_all_embeddings_by_project_id(project_id) |
| 351 | + |
| 352 | + for embedding_item in all_embeddings: |
| 353 | + embedding_manager.request_tensor_upload(project_id, str(embedding_item.id)) |
| 354 | + notification.send_organization_update(project_id, "records_changed") |
| 355 | + |
| 356 | + except Exception: |
| 357 | + print(traceback.format_exc(), flush=True) |
0 commit comments