-
-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement closure-tree to improve performance. #34
Comments
@Timurkhan thank you for reporting your experience with this library. The ordering problem was really hard to solve because the objective was to sort an N levels data structure which is stored in a flat data-structure (just 1 db table) and at the same time each object must respect the order of its ancestors. I understand that the solution is not very transparent but it solves the problem well, if you have any idea on how to obtain the same result in a better way feel free to share it. The Please try to import your data using the |
I will think about how to solve the problem. I've tried all the options. First, I assigned the tn_priority a order number in the list of node . Secondly, I tried to duplicate the id in the same field. Nothing helped. All the time, sorting occurs in the reverse order of id. |
I have a quick idea. It doesn't require a lot of code change.
In this case, sorting will occur correctly when the ordinal number of the node in the children of this node is specified in the tn_priority field. This will slow down the already not very fast insertion of the node, but I think it will be also useful for issuing the Materialized Path without traversing the tree. |
This doesn't seem to be more a more transparent solution :) Anyway, before the current implementation, I stored the ordering string in a db field, but it could become very long in case of deep structures, especially if the pk is a I agree with the fact that |
Yes: of course! The combined field must in any case unambiguously specify the order of the element in the list of the node's children. |
@Timurkhan have you any update on this? |
Befor NY I will sent u vertion. Now in testing |
Hi Fabio!
It doesn't seem to work badly. The main thing is that it allows you to explicitly specify the order of the entries in the tree. |
@Timurkhan thank you for the feedback, I will test it and let you know! |
Hi @fabiocaccamo!
|
Hello @TimurKady, thank you for the update, the code seems pretty clear, I will test it as soon as possible. |
Tnx! |
@TimurKady there already an issue for that, check #37 |
I've adjusted the code a bit. Colleagues made a small bug. Sorry. |
@TimurKady I tried to test your code, but trying to run the test suite ( |
To be honest, in any case, the main drawback of the library is the high cost of creating one record. We looked at the reason. You completely rebuild the tree when you insert each element with post_save. I already thought about making changes to the code. To do this, will have to change two methods (.save() anl __get_node_data()) and abandon the signals. But the costs are very high. Meybe leter... |
This is what I needed to know, thanks! |
But I really like your idea, to store the answers to the most likely requests in the database. Maybe later, when I have time, I will try to offer you an adjusted faster solution based on your idea. |
@TimurKady When I initially developed this library my need was to manage quickly a 4 levels menu (less than 200 entries) with a nice admin integration, so I come up to this solution and I used it in different projects always for solving the same problem. Now looking at feedbacks, many devs are using it with very big trees with thousands of records, so performances are a top-priority issue to solve. Updating the whole tree is not a scalable solution, now something more smart that continue to satisfy the tests is needed, not an easy task at all. Just for curiosity, have you tried to do the same with |
I have an idea, or rather a suggestion. There is one neat way to drastically improve the performance of your library. The essence of the method is the simultaneous use of the main Adjacency List and the Closure Table. Then you will not have to incur large costs when creating a new element, and the bulk of the requests will still be performed in one database request. If you don't mind, I'll have a free weekend so I can write most of the code. You will only need to add some methods that will ensure compatibility with earlier versions of the library and run tests. If you are in favor of this approach, then find a way to tell me your email address so that we can communicate not here, but directly. |
Yes, of course! I have tried all tree packages. But yours appealed to me the most. All other libraries have less advantages than disadvantages. |
@TimurKady It's an ambitious change, I didn't know about closure tables, it seems a very good approach, thank you for suggesting it. You can find my email on my GH profile. |
@fabiocaccamo Unfortunately, there is nothing ambitious in this. The code will not be too big. The most ambitious is the support of the previous version. I am well acquainted with graphs and algorithms for working with it. I'll close this part of the code. You know Django and cache working very well. Close this part! I'll send you my code and we will discuss everything. |
@TimurKady I have just discovered these packages: |
I'll look it later |
Combination of Adjacency List and Closure Table (django-treenode based) |
Hello!
I want to share the experience of using the module. Today I see many of its advantages and two main disadvantages. One of them I want to discuss. This is control over the order of elements.
Description of the problem.
The module does not have a transparent and understandable mechanism for ordering elements in the tree. In practice, the most common are two modes: alphabetical sorting and strict order set by the user. The logic dictates that the tn_priority field provided by the default form should do this. If it is set to 0 for all elements, then they must be ordered alphabetically. If it is specified, then the field value determines the order.
But alas, this is not the case.
Another method of establishing a coercive order of elements, which is intuitively prompted by experience, is also not suitable. This is an attempt to import data with the tn_order field set.
It would be nice if you made it easier to manage the order of items in tree.
PS. The main trouble is that with all my attachment to this module, without a mechanism for intelligible order management, I have to refuse to use it. And it just tears my soul to shreds :-(
Funding
The text was updated successfully, but these errors were encountered: