Skip to content

Allow an array of matches in the pattern matching rules #24

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 10 commits into
base: master
Choose a base branch
from

Conversation

x-m-el
Copy link
Contributor

@x-m-el x-m-el commented Jun 23, 2025

This allows setting multiple matches (a combination of subject, predicate and object) for one definition. The same can be achieved by creating multiple definitions with the same callback/options and a different single match pattern.
Using an object (instead of array) for a match is still allowed: this is backwards compatible.

This also changes two aspects of how deltas are sent through:
When a delta matches multiple patterns (matches), it will send the same change sets multiple times to the same url, for every match that is in the rules.
When using an array for matches, the change set will only be sent once.

When using in conjunction with sendMatchesOnly, all patterns matching those defined in matches will be sent in one change set together. When not using an array for matches, multiple change sets with "one type of match" each would be sent to the url.

Note: for ease of merging, this is build further upon #21, which is a PR for a fork. So this PR includes those commits as well (the base can't be set to the fork).
This code change could easily be changed to a change on master, as it changes a function that was only moved in #21.

The actual changes for this PR is the last commit.

nvdk and others added 9 commits January 23, 2025 10:50
this greatly reduces the size of delta messages in stacks with large data changes.
this tries to optimize filtering and match detection in two ways:
- by grouping on match pattern: this means we only do detection and filtering
once for a given match pattern (takes the pattern and sendMatchesOnly into
account)
- by doing matching before origin filter, since the latter seems more costly
this is not the prettiest of solutions, but it does achieve the same thing.
bonus is it only happens once on startup
it's mentioned in the expressjs best practices (and elsewhere) that process.env should be used sparingly:

| If you need to write environment-specific code, you can check the value of NODE_ENV with process.env.NODE_ENV. Be aware that checking the value of any environment variable incurs a performance penalty, and so should be done sparingly.
https://expressjs.com/th/advanced/best-practice-performance.html#set-node_env-to-production

it seems this is because process.env is a getter that processes the ENV array each time
@x-m-el x-m-el changed the title Allow an array of matches in the patern matching rules Allow an array of matches in the pattern matching rules Jun 23, 2025
This allows setting multiple matches (a combination of subject, predicate and object) for one definition. The same can be achieved by creating multiple definitions with the same callback/options and a different single match pattern.
Using an object (instead of array) for a `match` is still allowed: this is backwards compatible.

This also changes two aspects of how deltas are sent through:
When a delta matches multiple patterns (matches), it will send the same change sets multiple times to the same url, for every match that is in the rules.
When using an array for `match`es, the change set will only be sent once.

When using in conjunction with `sendMatchesOnly`, all patterns matching those defined in `match`es will be sent in one change set together. When not using an array for `match`es, multiple change sets with "one type of match" each would be sent to the url.
@x-m-el x-m-el force-pushed the allow-multiple-match-cases branch from fe49625 to 3981024 Compare June 23, 2025 08:41
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.

2 participants