2026-02-24 22:48:40 +02:00
|
|
|
import hashlib
|
|
|
|
|
|
|
|
|
|
from app.indexing_pipeline.connector_document import ConnectorDocument
|
|
|
|
|
|
|
|
|
|
|
2026-03-25 18:33:44 +05:30
|
|
|
def compute_identifier_hash(
|
refactor(backend): rename search_space -> workspace across app bulk (Phase 2 Wave D)
Scoped codemod over surfsense_backend/app (excluding routes/, Wave E): renames
search_space_id -> workspace_id, search_space -> workspace, SearchSpace -> Workspace
across services, utils, tasks, agents, gateway, event_bus, notifications, podcasts,
automations, observability params, and prompt .md files. Also flips the camelCase
payload key searchSpaceId -> workspaceId (no backend reader; hard cutover).
Preserved carve-outs (verbatim): Celery task names "delete_search_space_background"
and "ai_sort_search_space" (wire names), and the OTel/metric key "search_space.id"
(dashboards depend on it). Enum values 'SEARCH_SPACE' and SearchSourceConnector
untouched.
2026-06-26 18:30:47 +02:00
|
|
|
document_type_value: str, unique_id: str, workspace_id: int
|
2026-03-25 18:33:44 +05:30
|
|
|
) -> str:
|
|
|
|
|
"""Return a stable SHA-256 hash from raw identity components."""
|
refactor(backend): rename search_space -> workspace across app bulk (Phase 2 Wave D)
Scoped codemod over surfsense_backend/app (excluding routes/, Wave E): renames
search_space_id -> workspace_id, search_space -> workspace, SearchSpace -> Workspace
across services, utils, tasks, agents, gateway, event_bus, notifications, podcasts,
automations, observability params, and prompt .md files. Also flips the camelCase
payload key searchSpaceId -> workspaceId (no backend reader; hard cutover).
Preserved carve-outs (verbatim): Celery task names "delete_search_space_background"
and "ai_sort_search_space" (wire names), and the OTel/metric key "search_space.id"
(dashboards depend on it). Enum values 'SEARCH_SPACE' and SearchSourceConnector
untouched.
2026-06-26 18:30:47 +02:00
|
|
|
combined = f"{document_type_value}:{unique_id}:{workspace_id}"
|
2026-03-25 18:33:44 +05:30
|
|
|
return hashlib.sha256(combined.encode("utf-8")).hexdigest()
|
|
|
|
|
|
|
|
|
|
|
2026-02-24 22:48:40 +02:00
|
|
|
def compute_unique_identifier_hash(doc: ConnectorDocument) -> str:
|
2026-02-25 01:40:30 +02:00
|
|
|
"""Return a stable SHA-256 hash identifying a document by its source identity."""
|
2026-03-28 16:39:46 -07:00
|
|
|
return compute_identifier_hash(
|
refactor(backend): rename search_space -> workspace across app bulk (Phase 2 Wave D)
Scoped codemod over surfsense_backend/app (excluding routes/, Wave E): renames
search_space_id -> workspace_id, search_space -> workspace, SearchSpace -> Workspace
across services, utils, tasks, agents, gateway, event_bus, notifications, podcasts,
automations, observability params, and prompt .md files. Also flips the camelCase
payload key searchSpaceId -> workspaceId (no backend reader; hard cutover).
Preserved carve-outs (verbatim): Celery task names "delete_search_space_background"
and "ai_sort_search_space" (wire names), and the OTel/metric key "search_space.id"
(dashboards depend on it). Enum values 'SEARCH_SPACE' and SearchSourceConnector
untouched.
2026-06-26 18:30:47 +02:00
|
|
|
doc.document_type.value, doc.unique_id, doc.workspace_id
|
2026-03-28 16:39:46 -07:00
|
|
|
)
|
2026-02-24 22:48:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def compute_content_hash(doc: ConnectorDocument) -> str:
|
refactor(backend): rename search_space -> workspace across app bulk (Phase 2 Wave D)
Scoped codemod over surfsense_backend/app (excluding routes/, Wave E): renames
search_space_id -> workspace_id, search_space -> workspace, SearchSpace -> Workspace
across services, utils, tasks, agents, gateway, event_bus, notifications, podcasts,
automations, observability params, and prompt .md files. Also flips the camelCase
payload key searchSpaceId -> workspaceId (no backend reader; hard cutover).
Preserved carve-outs (verbatim): Celery task names "delete_search_space_background"
and "ai_sort_search_space" (wire names), and the OTel/metric key "search_space.id"
(dashboards depend on it). Enum values 'SEARCH_SPACE' and SearchSourceConnector
untouched.
2026-06-26 18:30:47 +02:00
|
|
|
"""Return a SHA-256 hash of the document's content scoped to its workspace."""
|
|
|
|
|
combined = f"{doc.workspace_id}:{doc.source_markdown}"
|
2026-02-24 22:48:40 +02:00
|
|
|
return hashlib.sha256(combined.encode("utf-8")).hexdigest()
|