-
Notifications
You must be signed in to change notification settings - Fork 483
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
Allow indexing on nested fields #718
Conversation
Thanks @Moocar , I have been offline for a while but I hope to look this over soon. |
Thanks @obeliskos for all your great work on Loki! Excited to have this in Gatsby soon. |
Great, thanks @Moocar AND @KyleAMathews! Since this is performance rather than functional related, I will leave option of creating a unit test now or in the future up to you. |
@obeliskos thanks! Funny you should mention tests, I just found a bug where nested indexed fields aren't handling the |
This PR adds a feature flag `GATSBY_DB_NODES` that can be used to change the storage engine for the gatsby data layer (`nodes`). - `redux` (default) which uses the existing redux implementation, and `sift` for querying. Or, you can use - `loki` which uses the loki in-memory database to store and query. This PR re-implements functionality in #9338, but with all tests passing and addressing previous feedback. It should also be easier to review since it builds on several refactorings. Some things to note: 1. I [submitted a PR to lokijs](techfort/LokiJS#718) which still hasn't been merged, though the author says he'll start working on it soon. Therefore, in in interim, I've published [@moocar/lokijs](https://www.npmjs.com/package/@moocar/lokijs). 1. I haven't implemented auto indexing of query fields yet. I'll attack that next. 1. I suggest we ask the community to try out the feature flag once it's merged to get feedback. All the tests pass, but this is such a big change that we'll want to test it gradually 1. While loki uses the same mongo query language as sift, they do have different behavior. Most of my time on this PR was spent ensuring that loki behaves **exactly** like sift. See [db/loki/nodes-query.js](https://github.com/gatsbyjs/gatsby/blob/cddbe893a4ce638babb1cbe5e5da4c13b6f5e57d/packages/gatsby/src/db/loki/nodes-query.js). But there's a chance a few edge cases have slipped through the cracks. 1. the feature flag works with the tests too `GATSBY_DB_NODES=loki yarn test`. We should perhaps look into running this on all PRs
This PR adds a feature flag `GATSBY_DB_NODES` that can be used to change the storage engine for the gatsby data layer (`nodes`). - `redux` (default) which uses the existing redux implementation, and `sift` for querying. Or, you can use - `loki` which uses the loki in-memory database to store and query. This PR re-implements functionality in gatsbyjs#9338, but with all tests passing and addressing previous feedback. It should also be easier to review since it builds on several refactorings. Some things to note: 1. I [submitted a PR to lokijs](techfort/LokiJS#718) which still hasn't been merged, though the author says he'll start working on it soon. Therefore, in in interim, I've published [@moocar/lokijs](https://www.npmjs.com/package/@moocar/lokijs). 1. I haven't implemented auto indexing of query fields yet. I'll attack that next. 1. I suggest we ask the community to try out the feature flag once it's merged to get feedback. All the tests pass, but this is such a big change that we'll want to test it gradually 1. While loki uses the same mongo query language as sift, they do have different behavior. Most of my time on this PR was spent ensuring that loki behaves **exactly** like sift. See [db/loki/nodes-query.js](https://github.com/gatsbyjs/gatsby/blob/cddbe893a4ce638babb1cbe5e5da4c13b6f5e57d/packages/gatsby/src/db/loki/nodes-query.js). But there's a chance a few edge cases have slipped through the cracks. 1. the feature flag works with the tests too `GATSBY_DB_NODES=loki yarn test`. We should perhaps look into running this on all PRs
Is the use of this documented (preferably a walk-through)? |
Loki doesn't support indexing on nested fields (period-delimited). This PR adds support for it.
The main change is the addition of the
Utils.getIn
function which performs the deep lookup functionality. Initially, I replaced allobject[path]
lookups with this function, but that resulted in a 2x performance penalty due to thestring.split('.')
that was required for each lookup. So instead, I added a flagusingDotNotation
that can be set so that the function knows whether it needs to split the path at all.I've been testing it on https://www.gatsbyjs.org/ as a replacement for the in-memory DB and it's working great so far.