From 10470a66b71fc64657873b5a65d5dde88d5b32be Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 21 Sep 2011 18:03:23 +0530 Subject: [PATCH] commit after every 100 in rebuild_tree --- cgi-bin/webnotes/utils/nestedset.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/cgi-bin/webnotes/utils/nestedset.py b/cgi-bin/webnotes/utils/nestedset.py index 97cf156074..dc212b74a1 100644 --- a/cgi-bin/webnotes/utils/nestedset.py +++ b/cgi-bin/webnotes/utils/nestedset.py @@ -37,19 +37,26 @@ def rebuild_tree(doctype, parent_field): for r in result: right = rebuild_node(doctype, r[0], right, parent_field) -def rebuild_node(doctype, parent, left, parent_field): +def rebuild_node(doctype, parent, left, parent_field, cnt = 0): # the right value of this node is the left value + 1 - right = left+1 + right = left+1 # get all children of this node result = webnotes.conn.sql("SELECT name FROM `tab%s` WHERE `%s`='%s'" % (doctype, parent_field, parent)) for r in result: - right = rebuild_node(doctype, r[0], right, parent_field) + right = rebuild_node(doctype, r[0], right, parent_field, cnt) # we've got the left value, and now that we've processed # the children of this node we also know the right value webnotes.conn.sql('UPDATE `tab%s` SET lft=%s, rgt=%s WHERE name="%s"' % (doctype,left,right,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 right+1