dabo Commit
Revision 6940
Date: 2011-10-27 15:55:07 -0700 (Thu, 27 Oct 2011)
Author: Paul
Trac: http://trac.dabodev.com/changeset/6940

Changed:
U   trunk/dabo/biz/dBizobj.py

Log:
(Re)Implemented fast and precise versions of _isAnyChanged(), and made a wrapper
isAnyChanged() that first tries the fast version, and only proceeds with the 
precise function if the fast function returned True.

This results in some extra overhead when there are changed records, but I tested
with a bizobj that is deep and wide, and closing out of the form with no changes
takes about a second instead of about 30 seconds before this change, and we may
be partially there to having the best of both worlds (precise and fast).


Diff:
Modified: trunk/dabo/biz/dBizobj.py
===================================================================
--- trunk/dabo/biz/dBizobj.py   2011-10-27 21:44:53 UTC (rev 6939)
+++ trunk/dabo/biz/dBizobj.py   2011-10-27 22:55:07 UTC (rev 6940)
@@ -1514,8 +1514,29 @@
                return False
 
 
-       def isAnyChanged(self, includeNewUnchanged=None, withChildren=True):
+       def _isAnyChanged_fast(self, includeNewUnchanged=None):
                """
+               INTERNAL USE ONLY: This checks all the cursors including the 
ones
+               out of context, and needs to be combined with the precise 
function
+               like: 
+                               if self._isAnyChanged() and 
self.isAnyChanged()...
+
+               Which will at least be much faster (and still correct) in the 
case of 
+               _isAnyChanged() returning False.
+               """
+               if includeNewUnchanged is None:
+                       includeNewUnchanged = self.SaveNewUnchanged
+               for cursor in self.__cursors.values():
+                       if cursor.isChanged(allRows=True, 
includeNewUnchanged=includeNewUnchanged):
+                               return True
+               for child in self._children:
+                       if 
child._isAnyChanged_fast(includeNewUnchanged=includeNewUnchanged):
+                               return True
+               return False
+
+
+       def _isAnyChanged_precise(self, includeNewUnchanged=None, 
withChildren=True):
+               """
                Return True if at least one record in the current record set 
                has been changed.
                """
@@ -1527,6 +1548,18 @@
                return ret
 
 
+       def isAnyChanged(self, includeNewUnchanged=None, withChildren=True):
+               """
+               Return True if at least one record in the current record set 
+               has been changed.
+               """
+               if not self._isAnyChanged_fast(includeNewUnchanged):
+                       ## the fast function never gives false negatives
+                       return False
+               ## must use precise function because fast function can return 
false positives:
+               return self._isAnyChanged_precise(includeNewUnchanged, 
withChildren)
+
+
        def isChanged(self, includeNewUnchanged=None, withChildren=True):
                """
                Return True if data has changed in this bizobj and any children.



_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev
Searchable Archives: http://leafe.com/archives/search/dabo-dev
This message: 
http://leafe.com/archives/byMID/[email protected]

Reply via email to