Storing the materialized path for tree structures in the Payload Nested Docs Plugin to work with nested subtrees #13358
MurzNN
started this conversation in
Feature Requests & Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Now the Payload Nested Docs plugin stores only the parent id in the database - this is a lightweight storage and enough for simple use cases and small structures.
But when it comes to displaying a subtree or searching within subtrees, it becomes a pain with this type of storage!
For example, I have a large knowledge base tree with 1000 pages, having a tree with 10 levels of nesting.
And I just need to display the current page and all the child pages of this page as a multi-level subtree.
Having only the "parent" field, we will need to make many consequence queries to the database to retrieve all child pages for this page - one for each subtree, and this will be a performance killer.
The great solution for this is to store not only the "parent" id value, but also the path to the current page from the root, as a materialized path pattern, or as an array of ancestors. Here is a good explanation of different techniques to store tree structures in the databases: https://www.mongodb.com/docs/manual/applications/data-models-tree-structures/
So, to allow querying for subtrees would be good to add an option to the Payload Nested Docs to store also the full path to the element, using the Materialized Paths approach (supported by all databases) or the Array of Ancestors (supported by MongoDB and PostgreSQL).
Beta Was this translation helpful? Give feedback.
All reactions