To improve performance, skip validating subschemas in oneOf / anyOf if formData is undefined - #2676
Conversation
|
@epicfaace , I have added a test to utils_test.js, in which I pass undefined as formData to getMatchingOption(), and it returns 0. My point is, if we dont pass formData to getMatchingOption => then there is no need to validate data against the whole schema. In my schema, I use anyOfs (100 to 200 anyOfs) , and the check in utils.js passes undefined as formData as shown in the below pic. I also have a very large schema and multiple checks to validate formData against schema is very slow. Maybe this is not the right solution, I can pass you my huge schema and you can paste it in playground and see it takes lot of time to load, eventually it loads after 3 minutes. https://github.com/terminusdb/terminusdb-documents-ui/blob/main/seshatSchema.json Any help would be really appreciated, we can set up a call as well, but do let me know what has to be done. Thank you so much :) |
|
Ok, thanks @epicfaace, I shall join the call on discord this Friday 11 am ET :) |
| delete augmentedSchema.required; | ||
|
|
||
| if (isValid(augmentedSchema, formData, rootSchema)) { | ||
| if (formData && isValid(augmentedSchema, formData, rootSchema)) { |
There was a problem hiding this comment.
At the beginning of the function -- let's add:
// For performance, skip validating subschemas if formData is undefined. We just
// want to get the first option in that case.
if (formData === undefined) {
return 0;
}
There was a problem hiding this comment.
And remove the other changes in this file.
epicfaace
left a comment
There was a problem hiding this comment.
Thanks! Can you fix the lint so the CI passes?
|
@epicfaace ok I have fixed the lint issues :) |
|
I have a question about that - is it fix that issue too? #1564 |
|
The linter issues should be fixed. 😄 |
|
@epicfaace, Hello, Can you contact me on discord (Kitty Jose). I would like to discuss a matter with you. I cant seem to find ur username on discord.Thanks :D |
|
I'm not sure what your discord username is -- mine is Ashwin#0168. |
epicfaace
left a comment
There was a problem hiding this comment.
Can you update this branch with the latest from master and add an entry to CHANGELOG.md?
56dc455 to
3971c20
Compare
|
We added an entry to the changelog and rebased to master. 😄 |
|
|
||
| ## @rjsf/core | ||
|
|
||
| - For performance, skip validating subschemas if formData is undefined (#2676) |
There was a problem hiding this comment.
| - For performance, skip validating subschemas if formData is undefined (#2676) | |
| - To improve performance, skip validating subschemas in oneOf / anyOf if formData is undefined (#2676) |
There was a problem hiding this comment.
Can you make this change? I don't have access to edit. Thanks!
|
|
||
| ## @rjsf/core | ||
|
|
||
| - For performance, skip validating subschemas if formData is undefined (#2676) |
There was a problem hiding this comment.
Can you make this change? I don't have access to edit. Thanks!
|
Did the change 👍 Also merged with the latest |
Fixing getMatchingOption in the case of oneOf/anyOf by validating schema only when formData is available
add proper return on formData check in getMatchingOption()
Test utils when formData is undefined
For performance, skip validating subschemas if formData is undefined. We just want to get the first option in that case. moving formData check to beginning of getMatchingOption()
Add a test for getMatchingOption
where formData is null
Where option 2 is {type: null}
We expect getMatchingOption to be equal to 2
after fixing lint errors
0221c89 to
9b38d3a
Compare

Fixing getMatchingOption in the case of oneOf/anyOf by validating schema only when formData is available
Reasons for making this change
When there is a property with oneOf/anyOf - schema gets validated when there is not formData provided which leads to lot of load time. This fix will improves speed and performance.