Complete publish preview Phase 2A with retention, refresh and cache consistency
This commit is contained in:
@@ -18,6 +18,24 @@ from app.services.scheme_validation import build_scheme_validation_report
|
||||
from app.services.structure_diff import build_structure_diff
|
||||
|
||||
|
||||
def _serialize_artifacts(artifacts_rows: list) -> dict:
|
||||
return {
|
||||
"total": len(artifacts_rows),
|
||||
"items": [
|
||||
{
|
||||
"artifact_id": row.artifact_id,
|
||||
"artifact_type": row.artifact_type,
|
||||
"artifact_variant": row.artifact_variant,
|
||||
"status": row.status,
|
||||
"storage_path": row.storage_path,
|
||||
"meta_json": row.meta_json,
|
||||
"created_at": row.created_at.isoformat(),
|
||||
}
|
||||
for row in artifacts_rows
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
async def build_publish_preview_bundle(
|
||||
*,
|
||||
scheme_id: str,
|
||||
@@ -62,21 +80,7 @@ async def build_publish_preview_bundle(
|
||||
except Exception:
|
||||
unpriced += 1
|
||||
|
||||
artifacts = {
|
||||
"total": len(artifacts_rows),
|
||||
"items": [
|
||||
{
|
||||
"artifact_id": row.artifact_id,
|
||||
"artifact_type": row.artifact_type,
|
||||
"artifact_variant": row.artifact_variant,
|
||||
"status": row.status,
|
||||
"storage_path": row.storage_path,
|
||||
"meta_json": row.meta_json,
|
||||
"created_at": row.created_at.isoformat(),
|
||||
}
|
||||
for row in artifacts_rows
|
||||
],
|
||||
}
|
||||
artifacts = _serialize_artifacts(artifacts_rows)
|
||||
|
||||
pricing_coverage = {
|
||||
"snapshot_available": snapshot_available,
|
||||
@@ -126,10 +130,21 @@ async def get_or_build_publish_preview_bundle(
|
||||
scheme_version_id=scheme_version_id,
|
||||
baseline_override_scheme_version_id=baseline_override_scheme_version_id,
|
||||
)
|
||||
await save_publish_preview_artifact(
|
||||
|
||||
save_result = await save_publish_preview_artifact(
|
||||
scheme_id=scheme_id,
|
||||
scheme_version_id=scheme_version_id,
|
||||
payload=payload,
|
||||
baseline_scheme_version_id=payload["structure_diff"]["baseline_scheme_version_id"],
|
||||
)
|
||||
|
||||
artifacts_rows = await list_scheme_artifacts(scheme_version_id=scheme_version_id)
|
||||
payload["artifacts"] = _serialize_artifacts(artifacts_rows)
|
||||
payload["summary"]["has_artifacts"] = payload["artifacts"]["total"] > 0
|
||||
payload["summary"]["preview_cache_cleanup"] = save_result["cleanup"]
|
||||
|
||||
artifact = save_result["artifact"]
|
||||
path = Path(artifact.storage_path)
|
||||
path.write_text(json.dumps(payload, ensure_ascii=False, indent=2), encoding="utf-8")
|
||||
|
||||
return payload
|
||||
|
||||
Reference in New Issue
Block a user