feat: content_hash + дедупликация при загрузке
This commit is contained in:
+13
-4
@@ -2,12 +2,12 @@
|
||||
from .connection import query, execute, execute_returning
|
||||
|
||||
|
||||
def insert(filename, mime_type, original_bytes, status="uploaded", batch_id=None, zip_source=None):
|
||||
def insert(filename, mime_type, original_bytes, status="uploaded", batch_id=None, zip_source=None, content_hash=None):
|
||||
"""Insert document, return row dict."""
|
||||
return execute_returning(
|
||||
"""INSERT INTO documents (filename, mime_type, original_bytes, status, batch_id, zip_source)
|
||||
VALUES (%s, %s, %s, %s, %s, %s) RETURNING *""",
|
||||
(filename, mime_type, original_bytes, status, batch_id, zip_source),
|
||||
"""INSERT INTO documents (filename, mime_type, original_bytes, status, batch_id, zip_source, content_hash)
|
||||
VALUES (%s, %s, %s, %s, %s, %s, %s) RETURNING *""",
|
||||
(filename, mime_type, original_bytes, status, batch_id, zip_source, content_hash),
|
||||
)
|
||||
|
||||
|
||||
@@ -16,6 +16,15 @@ def get(doc_id):
|
||||
return rows[0] if rows else None
|
||||
|
||||
|
||||
def get_by_hash(batch_id, content_hash):
|
||||
"""Find document by content hash within batch."""
|
||||
rows = query(
|
||||
"SELECT id FROM documents WHERE batch_id = %s AND content_hash = %s LIMIT 1",
|
||||
(batch_id, content_hash),
|
||||
)
|
||||
return rows[0] if rows else None
|
||||
|
||||
|
||||
def set_parsed(doc_id, elements_json):
|
||||
"""Update elements_json + status='parsed'."""
|
||||
import json
|
||||
|
||||
Reference in New Issue
Block a user