Repository navigation
json2: strict module - #17927
json2: strict module#17927
Conversation
Co-authored-by: JalonSolov <JalonSolov@gmail.com>
Co-authored-by: Turiiya <34311583+tobealive@users.noreply.github.com>
Co-authored-by: Turiiya <34311583+tobealive@users.noreply.github.com>
| // REVIEW how performatic is it? | ||
| fn strict_check[T](json_data string) StructCheckResult { | ||
| $if T is $struct { | ||
| tokens := tokenize(json_data) | ||
|
|
||
| key_struct := get_keys_from_json(tokens) | ||
|
|
||
| mut duplicates := get_duplicates_keys(tokens, key_struct) | ||
| mut superfluous := get_superfluous_keys[T](tokens, key_struct) |
There was a problem hiding this comment.
One thing that comes to my mind would be to get the duplicates and superfluous in one loop. Both are recursively called, so it could be worth a try using one instead of multiple consecutive loops. Did you try that?
There was a problem hiding this comment.
I will try it in next PR. Thank you!!
Good work! It's likely not related π π |
|
Thank you for review @ttytm ! |
|
I do not understand, what is the use case of this submodule? |
|
I think we have a bug in the compiler, that allowed non public functions to be called by the test, without it being marked as an internal one. |
Many of the companies I worked for had slowdown issues due to excessive unnecessary data sent through the back-end of web applications. Using a library like this, on the front-end, for example, helps keep the back-end code fast, efficient, safe and with better-defined routes. Which results in a lower cost for projects in production |
|
I still do not understand the usecase π€ . Lets take for example a web app, and let it have: The communication between the JS client and the backend in V, happens by sending JSON messages. Where would such a module be used? If aa) is the case, could not the webserver just not generate the additional keys, in the first place, and that would have been caught in code review? If bb) is the case, what would the webserver do, when it detects it? Log that it found duplicated keys? Who will read those logs? Or will it stop processing, until the JS client is fixed? |
|
I also could not understand how is that related to routing at all π€ . |
Co-authored-by: Delyan Angelov <delian66@gmail.com>
Co-authored-by: Delyan Angelov <delian66@gmail.com>
|
Hi. Sorry the delay. I will answer everything As Soon As Possible |
It is very common for some developers to use a single route for multiple purposes, what is no good. For example, a route that returns all the products in the database, sometimes even with relationships, when, in many cases, they do not need all this information. Use the strict library to check that there is no unnecessary data, to perform end-to-end tests, send a log, or even return an error. It would help to create and maintain a final product with greater quality and performance, create a quality metric for the development team, facilitate code review... |
More the bb) case. It will depend on how rigid the team is. Personally, I would use Log Management or apply it to tests. Since, for me, it wouldn't be very interesting to break the application with errors that could be random (But it also depends on how these errors will be handled) |

This PR
Next PRs
strict_decode
prune
Performance improvments