Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize
#parent_id
Ancestry instance_method
If @ancestor_ids has already been calculated, using that value will be much more efficient for calculating the parent since the work translate the string to the proper typecasted value has already been done. But if it hasn't (for example, when calling `.arrange_nodes`), then ancestor_ids is never actually needed in full, and we can avoid the object allocations and CPU cycles needed to determine the depth by typecasting all of the ids in the string and just use a bit of substring manipulation to only allocate one object prior to typecasting (instead of N+1 for number of ancestors). Also, since it is possible for `@_parent_id` to be `nil`, make sure we are removing the instance variable instead of just setting it to `nil` if the location in the tree has been changed.
- Loading branch information