Spaces:
Sleeping
Sleeping
REFINE: replace inventory_cache references with instant_reply_cache for consistency in cache management
Browse files
services/document_service.py
CHANGED
|
@@ -11,7 +11,7 @@ from repositories.social_account import list_channel_identifiers_for_workspace
|
|
| 11 |
from repositories.workspace import get_workspace_id_by_slug
|
| 12 |
from rag.chunker import prepare_policy_chunks
|
| 13 |
from rag.embedder import delete_chunks_for_source, store_chunks
|
| 14 |
-
from services.cache_service import
|
| 15 |
from services.document_parser_service import SUPPORTED_MIME, parse_file
|
| 16 |
from services.file_download_service import download_file
|
| 17 |
|
|
@@ -28,10 +28,6 @@ def resolve_workspace_id(workspace_slug: str) -> str:
|
|
| 28 |
return get_workspace_id_by_slug(workspace_slug)
|
| 29 |
|
| 30 |
|
| 31 |
-
def ensure_workspace_exists(workspace_slug: str) -> str:
|
| 32 |
-
return resolve_workspace_id(workspace_slug)
|
| 33 |
-
|
| 34 |
-
|
| 35 |
def update_status(
|
| 36 |
document_id: str,
|
| 37 |
workspace_id: str,
|
|
@@ -93,7 +89,7 @@ def process_document(
|
|
| 93 |
chunk["document_id"] = document_id
|
| 94 |
|
| 95 |
store_chunks(chunks)
|
| 96 |
-
|
| 97 |
|
| 98 |
update_status(document_id, workspace_id, status="ready", chunks=len(chunks))
|
| 99 |
logger.info(f"Document embedded | id={document_id} | chunks={len(chunks)}")
|
|
@@ -104,10 +100,10 @@ def process_document(
|
|
| 104 |
update_status(document_id, workspace_id, status="failed", error=str(e))
|
| 105 |
|
| 106 |
|
| 107 |
-
def
|
| 108 |
cleared = 0
|
| 109 |
for identifier in list_channel_identifiers_for_workspace(workspace_id):
|
| 110 |
-
cleared +=
|
| 111 |
|
| 112 |
logger.info(f"Cache cleared for workspace={workspace_id} after document ingest | keys={cleared}")
|
| 113 |
|
|
@@ -132,7 +128,7 @@ def delete_document(document_id: str, workspace_slug: str) -> None:
|
|
| 132 |
delete_chunks_for_document(document_id)
|
| 133 |
delete_document_status(document_id)
|
| 134 |
|
| 135 |
-
|
| 136 |
logger.info(f"Document deleted | id={document_id}")
|
| 137 |
|
| 138 |
|
|
|
|
| 11 |
from repositories.workspace import get_workspace_id_by_slug
|
| 12 |
from rag.chunker import prepare_policy_chunks
|
| 13 |
from rag.embedder import delete_chunks_for_source, store_chunks
|
| 14 |
+
from services.cache_service import clear_instant_reply_cache, clear_instant_reply_cache_for_identifier
|
| 15 |
from services.document_parser_service import SUPPORTED_MIME, parse_file
|
| 16 |
from services.file_download_service import download_file
|
| 17 |
|
|
|
|
| 28 |
return get_workspace_id_by_slug(workspace_slug)
|
| 29 |
|
| 30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
def update_status(
|
| 32 |
document_id: str,
|
| 33 |
workspace_id: str,
|
|
|
|
| 89 |
chunk["document_id"] = document_id
|
| 90 |
|
| 91 |
store_chunks(chunks)
|
| 92 |
+
clear_document_product_result_cache(workspace_id)
|
| 93 |
|
| 94 |
update_status(document_id, workspace_id, status="ready", chunks=len(chunks))
|
| 95 |
logger.info(f"Document embedded | id={document_id} | chunks={len(chunks)}")
|
|
|
|
| 100 |
update_status(document_id, workspace_id, status="failed", error=str(e))
|
| 101 |
|
| 102 |
|
| 103 |
+
def clear_document_product_result_cache(workspace_id: str) -> None:
|
| 104 |
cleared = 0
|
| 105 |
for identifier in list_channel_identifiers_for_workspace(workspace_id):
|
| 106 |
+
cleared += clear_instant_reply_cache_for_identifier(identifier)
|
| 107 |
|
| 108 |
logger.info(f"Cache cleared for workspace={workspace_id} after document ingest | keys={cleared}")
|
| 109 |
|
|
|
|
| 128 |
delete_chunks_for_document(document_id)
|
| 129 |
delete_document_status(document_id)
|
| 130 |
|
| 131 |
+
clear_instant_reply_cache()
|
| 132 |
logger.info(f"Document deleted | id={document_id}")
|
| 133 |
|
| 134 |
|