-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
How we can remove sift.js #11184
Comments
Hiya! This issue has gone quiet. Spooky quiet. 👻 We get a lot of issues, so we currently close issues after 30 days of inactivity. It’s been at least 20 days since the last update here. If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not stale" to keep this issue open! Thanks for being a part of the Gatsby community! 💪💜 |
Not stale |
With this and this we should be able to solve the |
@stefanprobst Nice work adding |
An issue I've hit recently IMO is a fair bit of a blocker for entirely moving to lokiJS as well - #17935 |
So after some time the answer turns out: we remove both :) Sift was disabled in 2.23.0 (code concretely to be dropped later this week) and loki has been removed a while ago. I think we can close this issue. |
Summary
Exploration on how we can use loki.js for 100% of queries. Resulted from issue #11008
Problem and background
Currently, we have two methods of filtering down the nodes in a graphql query. redux/run-sift (sift) and loki/nodes-query.js (loki). The underlying libraries (sift and loki) are both pure data query engines. They simply filter down an array of objects using the specified filter. Loki is much faster for large data sets because it can use indexes. Therefore we hope to eventually use loki for all queries.
But in Gatsby, not all nodes have pure data. Some contain fields that must be "resolved" to get their real value. These include GraphQL fields declared by plugins (using the setFieldsOnGraphQLNodeType), or linked fields (field names ending in
___NODE
). This means that before running loki or sift, we must first iterate through all nodes and callresolve
on all these fields.When a query is run, we currently check if the filter includes these unresolved fields. If it doesn't, we execute using loki, but if it does, we use
run-sift
to perform the query. It will call resolve on all the fields, and pass the resulting "resolved nodes" into the sift query (see resolveNodes function). It also caches the resolved nodes (cache key is by type, nodes length, and filter args) so that we don't perform the same work if the query is performed again.Proposed Solution
The ideal approach is to "resolve" all fields on all nodes in loki before running queries. This would mean we wouldn't need to store any "resolved nodes" caches, resulting in a smaller memory footprint and less complex code. Here's how it would work:
resolvedFields
indb/nodes-query
that stores whether all nodes of a type have had their lazy fieldresolve
function called and the return result set in the loki collection. This var mirrors the structure of lazy-fields (Map of typeName -> set of fields)resolvedFields
,resolve
function for each query filter field (can probably reuserun-sift
resolveRecursive)resolvedFields
.type
Set to flag that all fields of that type have been resolved.resolvedFields
, then we know that all nodes in the loki collection have had their required fields resolvedConsiderations/Other Stuff:
gatsby develop
, if a node is added, it will also need resolving. So consider running the above logic on the node whenever theCREATE_NODE
event is emitted (ugly, might need more thought).run-sift
doesn't actually cover this since it caches the resolved nodes based on the size of the nodes collection. We could improve on this.run-sift
is performing an unneededresolveRecursive
when handling the case where the filter is a single{$eq: id}
(here).sift
for theelemMatch
operator as raised in chore(gatsby): update Sift to version 7 #11008.run-sift.js
The text was updated successfully, but these errors were encountered: