This repository has been archived by the owner on Feb 4, 2024. It is now read-only.
Snapshot directories by traversing root nodes recursively #4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This pull request implements the ability to "snapshot" directories.
The node program records the tree structure (files and sub-directories) of each directory passed as a parameter.
The directories passed as parameters are considered root nodes, and then the program recursively traverses each node and defines its children, which traverses each child and defines the child's children, and so on...
By doing so, we record the entire tree, from each directory.
We store that information in memory, as cache. This allows us to instantly return the entire tree, instead of computing it again and again.
Testing
http://localhost:3000
and make sure the JSON data matches your file directoriesNotes
This change can be optimized in the future.
Imagine passing two directories as parameters, one is
~/A
and the other is~/A/B
.At the moment, the program traverse both
~/A
and~/A/B
. However, we're traversing~/A/B
twice.This can be optimized by using memoization. That way we wouldn't have to re-traverse
~/A/B
. Instead, we can just point towards that Node.