Greetings
I am glad to announce that last weekend, after a long lull, my small release took place, but I dare to hope, the useful crafts - the
TheSortableTree gem (rails 3, rails 4).
TheSortableTree is a gem that helps organize the drawing of Nested Set trees. But the most important thing is that it allows you to easily and simply manage your Nested Set tree by conveniently dragging items to the right place.
')

In the current version of the heme solved the most important problem - the speed of rendering. Previously, it was monstrously slow. Now (on average) you can get the drawing speed of
1500-2000 nodes per second . I find this speed acceptable and sufficient for most application needs.
Below (if you're interested) is a little history of creating heme, thanks, plans, and a story about how open source projects are affected by drinking strong black tea in the evening after work.
PS:
Anonym , you may be surprised, but in this release of the heme I take you on the biggest role, although I practically don’t know you and maybe you never programmed in ruby.
A bit of history
I became interested in nested set and drawing it when I met ruby and ruby on rails. It was the year 2008.
If you remember, at that time the implementation of the nested set algorithm on ruby was in the initial state. We used nested set to form a comment tree. The main problem of working with nested sets was that there was actually no decent and fairly common solution for drawing trees. We cycled as they could.
At that moment I wanted to
draw trees with simple recursion . Why? Because this approach, in my opinion, is quite simple to implement,
understandable to understand and contains almost no magic.
In 2009-2010, the first version of the code for tree rendering was already running in my projects. Then the code was completely bad - the classic porridge of type and logic. I could not find time to clear the Augean stables. But!
The code worked .
At the end of 2011, I calculated the code, separated the logic from the presentation, and designed the first version of the heme. There were problems, but I was hoping for github's collective intelligence. In any case, I can say that in some respects the
code has become beautiful . But still terribly slow. I do not even want to remember these terrible numbers.
At the end of 2012, a casual conversation with hacker user
Anonym pushed me to the idea that my code works godlessly slowly and should not be so. And if before that I was waiting for a good uncle with github, who will tell me what needs to be changed in my code, then at that moment I was taken up by a wild interest: what is wrong?
Strange, but for some reason, after a virtual conversation with
Anonym in one of the branches of the Q & A Habr,
sitting at home over a cup of evening tea, I scrolled the main fragments of my code in my head and found a bottleneck.
The decision was so terribly simple that it even put me in a stupor for a while. That same evening, the heme was patched and the rendering speed increased dramatically.
The code has become fast.In January 2013, while on vacation, I designed a new version of the heme and uploaded it to the network. Now I see that there is interest in my craft and it is damn nice to me.
Acknowledgments
I am very grateful to all those who helped me with advice, patches, consultations and constructive criticism and skepticism: first of all these are habrazhiteli:
vorbiz ,
UseRifle and
Anonym .
Thanks to nobody
mjsarfatti for his
nestedSortable script on the basis of which dragging works in my gem.
Thanks
Ikonze for a couple of icons.
Thanks to my beloved wife for the unlimited support and the fact that she
feeds me
tasty while I live in the virtual world.
Plans
Now I see several main areas to work on:
1. I cut a helper from a heme that creates a simple template for tree comments. In my opinion, such functionality should immediately be rendered into a separate gem, based on my gem. Although such solutions are probably already complete. And here it is worth seriously thinking.
2. There are many other solutions for tree data structures -
acts_as_ordered_tree ,
ancestry . It would be nice to make a version of the heme and for them.
3. Many people want to draw the main nodes of the tree in large trees, and then (if necessary) load the child elements. Such functionality, of course, is worth implementing. I probably will be doing this soon.
Little about the boundary conditions
I found that dragging on the client begins to significantly slow down if there are more than 1500 dragged nodes (adjust for technical resources). This is just information for consideration. So far, this problem is not relevant for me personally and I will not attach significant importance to it. However, it may be useful to you. Just know the order of the numbers.
Total
Overall, I am pleased with what happened. I hope my little handiwork will make life easier for someone.
Of course I hope for constructive criticism, reviews and issues on the project page.
Successes and good luck!