-
-
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
Queries getting slower during progress #45
Comments
@juliandehne how many nodes are there in the tree? |
Up to 2000 at times. With maybe 50 trees. |
You might be running into the same problem I'm running to: nodes without parents are considered as siblings --> each time you add a new node without a parent, all siblings will have to be updated --> This is also creating a problem on existing DBs that start using @juliandehne could you run |
@MichaelAkvo thank you for pointing to the possible cause.
# update siblings
if obj_data['tn_parent_pk']:
siblings_parent_key = str(obj_data['tn_parent_pk'])
obj_data['tn_siblings_pks'] = list(
objs_pks_by_parent.get(siblings_parent_key, []))
obj_data['tn_siblings_pks'].remove(obj_data['pk'])
obj_data['tn_siblings_count'] = len(obj_data['tn_siblings_pks']) The tree is automatically updated at the end of the |
Hi @fabiocaccamo,
I'm a little split because it depends on the point of view. Personally, I do not consider them siblings.
I tested it and it fixed part of the performance issue I was facing, however I still had to turn off signals and call That was after inserting the 101rst node.
|
@MichaelAkvo thank you for the great feedback. From a logical point of view neither me I consider them siblings, but let's imagine the scenario where root nodes represents pages or main menu entries, aren't them siblings? For turning off signals there is already a context manager, but I've not documented it in the README... from treenode.signals import no_signals
with no_signals():
# do stuff
pass
YourModel.update_tree() Concerning the I think that these could be some improvements:
|
Concerning menus, if there were a However, I noticed that even removing siblings from root nodes (which should still be done, imo) the problem would persist for wide trees / tree levels with many siblings. It looks like
With these changes, hopefully |
I agree with you regarding the menu scenario, however this would be surely a breaking change.
If you are interested, there is already a similar discussion on |
@juliandehne @MichaelAkvo have you any news on this? |
Hi @fabiocaccamo, Unfortunately there wasn't enough time to continue looking into this, so I went with a postgresql ltree solution. My branch still exists, so if you want to, you can use what you deem useful. Basically it uses Lots of tests are broken though since the ordering is now different. Modifying a tree should also update all nodes in the tree because the ancestors and descendants are kept track of in all nodes of that tree - however that doesn't seem to be happening, so either it's a bug or I'm misunderstanding the code. In any case, good luck with the performance improvements. |
@MichaelAkvo thank you very much for the feedback! |
Hi @fabiocaccamo, it should only call nodes linked to the same tree, to avoid loading taking too long. The other thing you'd need to do is disable the cache so you don't have to update it anymore, to avoid overloading the database when you do a simple node.get_ancestors() or whatever. Do you have any workarounds for this problem? |
@Nathan-Cohen I understand the problem and I like the idea of implementing an |
Thank you for providing this nice library. I am using it in a scientific project for twitter analysis. However, the db inserts seem to slow down a lot after a couple of days running it in production mode:
[treenode] update delab.models.Tweet tree: executed 0 queries in 71.44206510693766s.
[treenode] update delab.models.Tweet tree: executed 0 queries in 71.87405565101653s.
[treenode] update delab.models.Tweet tree: executed 0 queries in 66.6588648010511s.
[treenode] update delab.models.Tweet tree: executed 0 queries in 71.47152532404289s.
[treenode] update delab.models.Tweet tree: executed 0 queries in 79.63660701399203s.
I opened the issue also within my project, if you are interested in the way the library is used:
juliandehne/delab#15
Probably, I will write a unit test to verify it is an issue with the treenode library.
Any ideas?
The text was updated successfully, but these errors were encountered: