Last active
August 29, 2015 14:15
-
-
Save halfer/c09ac1fc2b4b01b3be1e to your computer and use it in GitHub Desktop.
Suggested plan for nested set prototype
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* Create working NS implementation | |
- The basic algorithm just requires 'left' and 'right' nodes, but it is a good idea to add in a | |
'parent' node, as this simplifies some of the SQL | |
- There are plenty of implementations on the web already, check GitHub and do a search | |
* Add the per-node columns as discussed on Stack Overflow | |
- 'table_name' for table, 'primary_key' for ID | |
* Add some data tables | |
- 'customer', 'address', 'book', etc. | |
* Write some code to handle a hierarchical string expression | |
- Convert an expression like `customer.address.postcode` to three levels of hierarchy plus a value | |
(or this could be two levels and the last one is just detected as a column) | |
- the postcode would go in the address table | |
* Add some test data | |
- customer.name | |
- customer.address.line1 | |
- customer.address.postcode | |
* Write some code to read a hierarchical string expression | |
- From 'customer.address.postcode' you'd expect a string | |
- From 'customer.address' that's a row (i.e. an array/object) | |
- From 'customer' that's a nested array/object | |
- Your nested set implementation will help here (getChildren/getDescendants etc) | |
* Work on how to share nodes | |
- Create two customers and give them different favouriteBooks with the same author | |
- Create two customers and get them to share the same favourite book | |
* Decide how your 'persistence' flag is going to work | |
- Is this per node? | |
- Do you walk down a hierarchy path and, when encountering this flag = true, share the remainder of the | |
descendent path? | |
- This bit is probably dependent on your requirements, but I'll try to advise if I can | |
* Shared node amendment | |
- If you delete any element from a shared node (except a column) you'll need to delete those references | |
from the tree for all nodes that refer to this | |
- If you add an element into a shared node, you'll need to add those references to to each tree that refers | |
to it | |
* Load testing | |
- Add in test data of the sizes you expect (1000 rows? 1M rows?) | |
- What are the response times? Are they acceptable? Will they work on your hardware? | |
The trick with prototypes is: | |
- Do them quickly | |
- Reuse as much code as you can | |
- Don't reinvent the wheel | |
- Be willing to throw them away if they don't work |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment