|
@@ -263,39 +263,34 @@ def rebuild_tree(doctype, parent_field): |
|
|
call rebuild_node for all root nodes |
|
|
call rebuild_node for all root nodes |
|
|
""" |
|
|
""" |
|
|
# get all roots |
|
|
# get all roots |
|
|
|
|
|
webnotes.conn.auto_commit_on_many_writes = 1 |
|
|
|
|
|
|
|
|
right = 1 |
|
|
right = 1 |
|
|
result = webnotes.conn.sql("SELECT name FROM `tab%s` WHERE `%s`='' or `%s` IS NULL ORDER BY name ASC" % (doctype, parent_field, parent_field)) |
|
|
result = webnotes.conn.sql("SELECT name FROM `tab%s` WHERE `%s`='' or `%s` IS NULL ORDER BY name ASC" % (doctype, parent_field, parent_field)) |
|
|
for r in result: |
|
|
for r in result: |
|
|
right = rebuild_node(doctype, r[0], right, parent_field) |
|
|
right = rebuild_node(doctype, r[0], right, parent_field) |
|
|
webnotes.conn.sql("commit") |
|
|
|
|
|
webnotes.conn.sql("start transaction") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
webnotes.conn.auto_commit_on_many_writes = 0 |
|
|
|
|
|
|
|
|
def rebuild_node(doctype, parent, left, parent_field, cnt = 0): |
|
|
|
|
|
|
|
|
def rebuild_node(doctype, parent, left, parent_field): |
|
|
""" |
|
|
""" |
|
|
reset lft, rgt and recursive call for all children |
|
|
reset lft, rgt and recursive call for all children |
|
|
""" |
|
|
""" |
|
|
from webnotes.utils import now |
|
|
from webnotes.utils import now |
|
|
n = now() |
|
|
n = now() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# the right value of this node is the left value + 1 |
|
|
# the right value of this node is the left value + 1 |
|
|
right = left+1 |
|
|
right = left+1 |
|
|
|
|
|
|
|
|
# get all children of this node |
|
|
# get all children of this node |
|
|
result = webnotes.conn.sql("SELECT name FROM `tab%s` WHERE `%s`='%s'" % (doctype, parent_field, parent)) |
|
|
result = webnotes.conn.sql("SELECT name FROM `tab%s` WHERE `%s`='%s'" % (doctype, parent_field, parent)) |
|
|
for r in result: |
|
|
for r in result: |
|
|
right = rebuild_node(doctype, r[0], right, parent_field, cnt) |
|
|
|
|
|
|
|
|
right = rebuild_node(doctype, r[0], right, parent_field) |
|
|
|
|
|
|
|
|
# we've got the left value, and now that we've processed |
|
|
# we've got the left value, and now that we've processed |
|
|
# the children of this node we also know the right value |
|
|
# the children of this node we also know the right value |
|
|
webnotes.conn.sql("UPDATE `tab%s` SET lft=%s, rgt=%s, modified='%s' WHERE name='%s'" % (doctype,left,right,n,parent)) |
|
|
webnotes.conn.sql("UPDATE `tab%s` SET lft=%s, rgt=%s, modified='%s' WHERE name='%s'" % (doctype,left,right,n,parent)) |
|
|
|
|
|
|
|
|
# commit after every 100 |
|
|
|
|
|
cnt += 1 |
|
|
|
|
|
if cnt % 100 == 0: |
|
|
|
|
|
cnt = 0 |
|
|
|
|
|
webnotes.conn.sql("commit") |
|
|
|
|
|
webnotes.conn.sql("start transaction") |
|
|
|
|
|
|
|
|
|
|
|
#return the right value of this node + 1 |
|
|
#return the right value of this node + 1 |
|
|
return right+1 |
|
|
return right+1 |
|
|
|
|
|
|
|
|