TheSortableTree 2.0 Gem Release

    Greetings!

    I am pleased to announce that last weekend, after a long lull, my small, but I dare to hopefully, useful craft - TheSortableTree gem (rails 3, rails 4) was released.

    TheSortableTree is a gem that helps organize the rendering 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 and dropping items to the right place.

    image

    In the current version of the gem, the most important problem has been solved - rendering speed. She used to be monstrously slow. Now (on average) you can get the rendering speed of 1500-2000 nodes per second . I find this speed acceptable and sufficient for most application needs.

    Below (if you are interested) a little history of creating a gem, 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 might be surprised, but in this gem release I will give you the biggest role, although I practically do not know you and maybe you have never programmed ruby.



    A bit of history


    My interest in the nested set and its rendering appeared at the same time when I met ruby ​​and ruby ​​on rails. This was the year 2008.

    If you remember, at that time the implementation of the nested set algorithm on ruby ​​was in its initial state. We used the nested set to form the comment tree. The main problem with working with nested sets was that there was practically no decent and fairly common solution for rendering trees. We cycled as best we 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 and practically does not contain magic.

    In 2009-2010, the first version of the code for drawing trees was already working in my projects. Then the code was really bad - a classic mess of sight 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 gem. There were problems, but I was hoping for the collective mind of github. In any case, I can say that in some respects the code has become beautiful . But still terribly slow. I don’t even want to remember these scary numbers.

    At the end of 2012, a random conversation with the anonym user Anonymled me to the idea that my code is shamelessly slow and should not be like that. 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 puzzled by 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 hub, while sitting at home with 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 got me into a stupor for a while. The gem was patched that evening and the rendering speed dramatically increased. The code has become fast.

    In January 2013, while on vacation, I designed a new version of the gem and put it on the net. Now I see that there is interest in my craft and it is damn nice for 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 harazhiteli: vorbiz , UseRifle and Anonym .

    Thanks to no one mjsarfatti for his nestedSortable script based on which drag and drop works in my gem.

    Thank you Iconza for a couple of icons.

    Thanks to my beloved wife for the unlimited support and the fact that she feeds me deliciously while I live in a virtual world.

    Plans


    Now I see several main areas worth working on:

    1. I cut out a helper from the gem, creating a simple template for tree comments. In my opinion, such functionality should immediately be taken out into a separate gem based on my gem. Although such decisions 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 gem and for them.

    3. Many people want large trees to be able to draw the main nodes of the tree, and then (if necessary) load the child elements. Such functionality, of course, is worth implementing. I’m likely to do this soon.

    A little bit about the boundary conditions


    I found that dragging and dropping on the client starts to slow down significantly if there are more than 1,500 dragged nodes (make allowance for technical resources). This is just information for consideration. So far, this problem is not relevant for me personally and I will not attach any significant significance to it. However, it may be useful to you. Just know the order of the numbers.

    Total


    In general, I am pleased with what happened. I hope my little craft makes life easier for someone.

    Of course I hope for constructive criticism, feedback and issues on the project page.

    Good luck and good luck!

    Also popular now: