wacrm/src/lib/flows
Arnas Donauskas dc58f71925
perf(flows): preload all flow_nodes once per dispatch
The advance loop called loadNode() on every iteration — one DB
round trip per node visited. A flow with 5 chained auto-advance
nodes (send_message → condition → set_tag → send_message → end)
cost 5 sequential round trips synchronous in the webhook hot path.
At ~50ms each that's 250ms before the customer sees anything.

Switch to a single upfront SELECT into a Map<node_key, FlowNodeRow>
keyed on the flow_id, passed through advanceFromNodeKey and
handleReplyForActiveRun. The advance loop is now in-memory and the
hot path costs one round trip regardless of chain length.

node_not_found semantics are preserved: missing keys still end the
run with that reason, same as the old per-node lookup.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-22 15:44:40 +03:00
..
admin-client.ts feat(flows): foundation for interactive WhatsApp messages (PR 1/4) 2026-05-22 13:12:27 +03:00
engine.test.ts feat(flows): templates + v1.5 nodes (collect_input/condition/set_tag) + run-history viewer (PR 4/4) 2026-05-22 14:27:01 +03:00
engine.ts perf(flows): preload all flow_nodes once per dispatch 2026-05-22 15:44:40 +03:00
fallback.test.ts feat(flows): runner engine + webhook integration + agent-handoff + cron sweep (PR 2/4) 2026-05-22 13:36:39 +03:00
fallback.ts feat(flows): runner engine + webhook integration + agent-handoff + cron sweep (PR 2/4) 2026-05-22 13:36:39 +03:00
feature-flag.test.ts feat(beta): per-account beta_features flag on profiles, gating Flows 2026-05-22 12:57:33 +03:00
feature-flag.ts feat(beta): per-account beta_features flag on profiles, gating Flows 2026-05-22 12:57:33 +03:00
meta-send.ts feat(flows): templates + v1.5 nodes (collect_input/condition/set_tag) + run-history viewer (PR 4/4) 2026-05-22 14:27:01 +03:00
templates.ts feat(flows): templates + v1.5 nodes (collect_input/condition/set_tag) + run-history viewer (PR 4/4) 2026-05-22 14:27:01 +03:00
types.ts feat(flows): templates + v1.5 nodes (collect_input/condition/set_tag) + run-history viewer (PR 4/4) 2026-05-22 14:27:01 +03:00
validate.test.ts feat(flows): no-code builder UI + flows API + validator (PR 3/4) 2026-05-22 13:57:38 +03:00
validate.ts feat(flows): templates + v1.5 nodes (collect_input/condition/set_tag) + run-history viewer (PR 4/4) 2026-05-22 14:27:01 +03:00