Skip to content

ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.

perf(deployments): skip unused plan parsing

Juan Denisa2901bf0643e
diff --git a/backend/app/models/deployment_job.py b/backend/app/models/deployment_job.py
index 73783b85..c40a0a8b 100644
--- a/backend/app/models/deployment_job.py
+++ b/backend/app/models/deployment_job.py
@@ -106,8 +106,10 @@ class DeploymentJob(RunLifecycleMixin, JsonColumnMixin, db.Model):
def to_dict(self, include_plan=False, include_logs=False):
result = self.get_result()
- plan = self.get_plan()
- recipe = plan.get('recipe') if self.kind == 'recipe.run' else None
+ plan = self.get_plan() if include_plan or self.kind == 'recipe.run' else None
+ recipe = (plan.get('recipe')
+ if self.kind == 'recipe.run' and isinstance(plan, dict)
+ else None)
handoff = result.get('handoff') if isinstance(result, dict) else None
data = {
'id': self.id,
diff --git a/backend/tests/test_deployments_unified.py b/backend/tests/test_deployments_unified.py
index 95423fbb..af8c4cd6 100644
--- a/backend/tests/test_deployments_unified.py
+++ b/backend/tests/test_deployments_unified.py
@@ -7,6 +7,8 @@ re-mounts the deployment-jobs surface under /deployments/jobs.
"""
import uuid
+from app.models.deployment_job import DeploymentJob
+
def test_deployment_job_link_columns_round_trip(app):
from app import db
@@ -25,6 +27,26 @@ def test_deployment_job_link_columns_round_trip(app):
assert 'deployment_id' in d and 'git_deployment_id' in d and 'webhook_id' in d
+def test_non_recipe_serialization_only_parses_an_explicitly_requested_plan(monkeypatch):
+ job = DeploymentJob(
+ id=str(uuid.uuid4()),
+ kind='deploy.install',
+ status='pending',
+ )
+ calls = []
+
+ def get_plan():
+ calls.append(True)
+ return {'steps': []}
+
+ monkeypatch.setattr(job, 'get_plan', get_plan)
+
+ assert 'plan' not in job.to_dict()
+ assert calls == []
+ assert job.to_dict(include_plan=True)['plan'] == {'steps': []}
+ assert calls == [True]
+
+
def _seed_app_with_deploys(app):
from app import db
from app.models import User