Skip to content

FIO-9783: refactor evaluator #245

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

brendanbond
Copy link
Contributor

@brendanbond brendanbond commented Apr 22, 2025

Link to Jira Ticket

https://formio.atlassian.net/browse/FIO-9783

Description

We've identified a bottleneck in the way we perform form validation in our Enterprise Server - creating VM contexts per request and executing the entire form orchestration pipeline in those contexts turns out to be kind of slow and expensive. To mitigate this, I've changed the way the Evaluator class is leveraged: instead of a static singleton class, it is now a mutable class instance that can be extended and overridden as needed, giving us access to things like constructors.

On a granular level, this PR:

  • removes the modules export and moves the Evaluator (formerly the JSONLogicEvaluator) into utilities;
  • encapsulates repeated evaluation and interpolation code (e.g. normalizing the context, etc.) into two convenience utility functions, evaluate and interpolate for use in the processors and elsewhere;
  • normalizes the context into only the values we can guarantee (previously we were passing the entire context into these evaluation contexts, which would mean that advanced evaluations would have access to/be able to mutate things like processor functions, etc.); and
  • adds an asynchronous version of the clearHidden processor, the lack of which I think was an oversight.

Breaking Changes / Backwards Compatibility

This introduces a fair amount of risk (although tests are passing) but there are certainly not any intentional breaking changes in this PR.

Dependencies

n/a

How has this PR been tested?

Tests are passing.

Checklist:

  • I have completed the above PR template
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (if applicable)
  • My changes generate no new warnings
  • My changes include tests that prove my fix is effective (or that my feature works as intended)
  • New and existing unit/integration tests pass locally with my changes
  • Any dependent changes have corresponding PRs that are listed above

…little more flexibility when extending evaluation behavior by converting the class from an entirely static class to a regular ES6 class. It also encapsulates repeated evaluation code (normalizing context, e.g.) into two convenience functions for evaluation and interpolation.
@brendanbond brendanbond force-pushed the FIO-9783-refactor-evaluator branch from 31d35ab to 1a17fe7 Compare May 2, 2025 20:28
@brendanbond brendanbond marked this pull request as ready for review May 2, 2025 20:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant