forked from mtusi2026/mtusi2026lab5
Добавить версионированный pipeline и проверку идемпотентности.
Трек 2 фиксирует дубль, устаревшую версию, падение до и после записи объекта и replay без второй копии результата. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+6
-4
@@ -34,13 +34,13 @@ def _public(row, variants=None) -> dict:
|
||||
}
|
||||
|
||||
|
||||
async def _variants(attachment_id) -> list:
|
||||
async def _variants(attachment_id, pipeline_version: int) -> list:
|
||||
async with db.require().acquire() as conn:
|
||||
rows = await conn.fetch(
|
||||
"""
|
||||
SELECT name, content_type, size_bytes, width, height, sha256
|
||||
FROM attachment_variants
|
||||
WHERE attachment_id = $1 AND pipeline_version = 1
|
||||
WHERE attachment_id = $1 AND pipeline_version = $2
|
||||
ORDER BY CASE name
|
||||
WHEN 'thumbnail' THEN 1
|
||||
WHEN 'crop' THEN 2
|
||||
@@ -49,6 +49,7 @@ async def _variants(attachment_id) -> list:
|
||||
END
|
||||
""",
|
||||
attachment_id,
|
||||
pipeline_version,
|
||||
)
|
||||
return [
|
||||
{
|
||||
@@ -64,7 +65,8 @@ async def _variants(attachment_id) -> list:
|
||||
|
||||
|
||||
async def present(row) -> dict:
|
||||
variants = await _variants(row["id"]) if row["status"] == "ready" else []
|
||||
version = int(row["applied_pipeline_version"]) if "applied_pipeline_version" in row.keys() else 1
|
||||
variants = await _variants(row["id"], version) if row["status"] == "ready" else []
|
||||
return _public(row, variants)
|
||||
|
||||
|
||||
@@ -175,7 +177,7 @@ async def get_for_member(attachment_id: str, user_id: str):
|
||||
"""
|
||||
SELECT a.id, a.chat_id, a.owner_id, a.filename, a.content_type,
|
||||
a.size_bytes, a.sha256, a.object_key, a.status, a.error_code,
|
||||
a.created_at, a.updated_at
|
||||
a.applied_pipeline_version, a.created_at, a.updated_at
|
||||
FROM attachments a
|
||||
JOIN chat_members m ON m.chat_id = a.chat_id AND m.user_id = $2
|
||||
WHERE a.id = $1
|
||||
|
||||
Reference in New Issue
Block a user