Small speed up to data entry flow steps (#105713)

Instead of checking if the flow is completed with
a linear tuple search each time, use a constant
set
This commit is contained in:
J. Nick Koston 2023-12-14 06:32:14 -10:00 committed by GitHub
parent ffb963c4c5
commit 0d9a583f4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -46,6 +46,15 @@ RESULT_TYPE_MENU = "menu"
# Event that is fired when a flow is progressed via external or progress source. # Event that is fired when a flow is progressed via external or progress source.
EVENT_DATA_ENTRY_FLOW_PROGRESSED = "data_entry_flow_progressed" EVENT_DATA_ENTRY_FLOW_PROGRESSED = "data_entry_flow_progressed"
FLOW_NOT_COMPLETE_STEPS = {
FlowResultType.FORM,
FlowResultType.EXTERNAL_STEP,
FlowResultType.EXTERNAL_STEP_DONE,
FlowResultType.SHOW_PROGRESS,
FlowResultType.SHOW_PROGRESS_DONE,
FlowResultType.MENU,
}
@dataclass(slots=True) @dataclass(slots=True)
class BaseServiceInfo: class BaseServiceInfo:
@ -407,14 +416,7 @@ class FlowManager(abc.ABC):
error_if_core=False, error_if_core=False,
) )
if result["type"] in ( if result["type"] in FLOW_NOT_COMPLETE_STEPS:
FlowResultType.FORM,
FlowResultType.EXTERNAL_STEP,
FlowResultType.EXTERNAL_STEP_DONE,
FlowResultType.SHOW_PROGRESS,
FlowResultType.SHOW_PROGRESS_DONE,
FlowResultType.MENU,
):
self._raise_if_step_does_not_exist(flow, result["step_id"]) self._raise_if_step_does_not_exist(flow, result["step_id"])
flow.cur_step = result flow.cur_step = result
return result return result