flows/planner: optimise db queries during plan building

This commit is contained in:
Jens Langhammer
2020-09-07 11:27:02 +02:00
parent 28893b9695
commit 87b14e8761
2 changed files with 10 additions and 13 deletions

View File

@ -156,25 +156,22 @@ class FlowPlanner:
if default_context:
plan.context = default_context
# Check Flow policies
for stage in (
self.flow.stages.order_by("flowstagebinding__order")
.select_subclasses()
.select_related()
):
binding: FlowStageBinding = stage.flowstagebinding_set.get(
target__pk=self.flow.pk
)
for binding in FlowStageBinding.objects.filter(
target__pk=self.flow.pk
).order_by("order"):
engine = PolicyEngine(binding, user, request)
engine.request.context = plan.context
engine.build()
if engine.passing:
LOGGER.debug("f(plan): Stage passing", stage=stage, flow=self.flow)
plan.stages.append(stage)
LOGGER.debug(
"f(plan): Stage passing", stage=binding.stage, flow=self.flow
)
plan.stages.append(binding.stage)
marker = StageMarker()
if binding.re_evaluate_policies:
LOGGER.debug(
"f(plan): Stage has re-evaluate marker",
stage=stage,
stage=binding.stage,
flow=self.flow,
)
marker = ReevaluateMarker(binding=binding, user=user)