Skip to content

Commit

Permalink
⚡ [#3855] Cache DMN calls
Browse files Browse the repository at this point in the history
  • Loading branch information
SilviaAmAm authored and sergei-maertens committed Feb 22, 2024
1 parent fa4a244 commit e5774b1
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions src/openforms/submissions/logic/actions.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
from __future__ import annotations

import json
from dataclasses import dataclass
from typing import Any, Mapping, TypedDict

from django.core.cache import cache
from django.core.serializers.json import DjangoJSONEncoder

from glom import assign
from json_logic import jsonLogic
from typing_extensions import Self
Expand Down Expand Up @@ -245,13 +249,24 @@ def eval(
for item in self.input_mapping
}

# Perform DMN call
dmn_outputs = evaluate_dmn(
definition_id=self.decision_definition_id,
version=self.decision_definition_version,
input_values=dmn_inputs,
plugin_id=self.plugin_id,
def _evaluate_dmn():
return evaluate_dmn(
definition_id=self.decision_definition_id,
version=self.decision_definition_version,
input_values=dmn_inputs,
plugin_id=self.plugin_id,
)

# Perform DMN call or retrieve result from cache
inputs = json.dumps(dmn_inputs, cls=DjangoJSONEncoder, sort_keys=True)
cache_key = hash(
str(submission.uuid)
+ self.decision_definition_id
+ self.decision_definition_version
+ self.plugin_id
+ inputs
)
dmn_outputs = cache.get_or_set(cache_key, default=_evaluate_dmn)

# Map DMN output to form variables
return {
Expand Down

0 comments on commit e5774b1

Please sign in to comment.