dabo Commit
Revision 4934
Date: 2009-01-16 18:50:23 -0800 (Fri, 16 Jan 2009)
Author: Ed
Trac: http://trac.dabodev.com/changeset/4934

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

Log:
Added the 'ChildCacheInterval' property to dBizobj. This controls how many 
seconds a child bizobj will skip requerying when the parent calls 
requeryAllChildren(). The default is not to cache, making it consistent with 
existing apps. But for web-enabled apps, the constant requerying is annoying 
and unnecessary in many cases. This allows you to control how often child 
requeries are carried out.


Diff:
Modified: trunk/dabo/biz/dBizobj.py
===================================================================
--- trunk/dabo/biz/dBizobj.py   2009-01-15 17:14:59 UTC (rev 4933)
+++ trunk/dabo/biz/dBizobj.py   2009-01-17 02:50:23 UTC (rev 4934)
@@ -2,6 +2,7 @@
 import types
 import re
 import warnings
+import time
 import dabo
 import dabo.dConstants as kons
 from dabo.db.dCursorMixin import dCursorMixin
@@ -80,7 +81,9 @@
                self._fillLinkFromParent = False
                self.exitScan = False
                self.dbapiCursorClass = None
+               self._childCacheInterval = None
 
+
                ##########################################
                ### referential integrity stuff ####
                ##########################################
@@ -1326,10 +1329,21 @@
                        if child.RequeryWithParent:
                                child.setCurrentParent()
                                if not 
child.isAnyChanged(useCurrentParent=True):
-                                       child.requery()
+                                       # Check for caching
+                                       if child.cacheExpired():
+                                               child.requery()
                self.afterChildRequery()
 
 
+       def cacheExpired(self):
+               """This controls if a child requery is needed when a parent is 
requeried."""
+               ret = True
+               if self._childCacheInterval:
+                       last = self._CurrentCursor.lastRequeryTime
+                       ret = ((time.time() - last) > self._childCacheInterval)
+               return ret
+
+
        def getPK(self):
                """ Return the value of the PK field."""
                if self.KeyField is None:
@@ -1872,6 +1886,13 @@
                self._caption = str(val)
 
 
+       def _getChildCacheInterval(self):
+               return self._childCacheInterval
+
+       def _setChildCacheInterval(self, val):
+               self._childCacheInterval = val
+
+
        def _getCurrentSQL(self):
                return self._CurrentCursor.CurrentSQL
 
@@ -2214,6 +2235,10 @@
        Caption = property(_getCaption, _setCaption, None,
                        _("The friendly title of the cursor, used in messages 
to the end user. (str)"))
 
+       ChildCacheInterval = property(_getChildCacheInterval, 
_setChildCacheInterval, None,
+                       _("""If this is a child bizobj, this represents the 
length of time in seconds that a 
+                       subsequent requery request will be ignored.  (int)"""))
+
        CurrentSQL = property(_getCurrentSQL, None, None,
                        _("Returns the current SQL that will be run, which is 
one of UserSQL or AutoSQL."))
 

Modified: trunk/dabo/db/dCursorMixin.py
===================================================================
--- trunk/dabo/db/dCursorMixin.py       2009-01-15 17:14:59 UTC (rev 4933)
+++ trunk/dabo/db/dCursorMixin.py       2009-01-17 02:50:23 UTC (rev 4934)
@@ -3,6 +3,7 @@
 
 import types
 import datetime
+import time
 import inspect
 import random
 import sys
@@ -68,6 +69,8 @@
                self.sortCase = True
                # Holds the last SQL run in a requery() call.
                self._lastSQL = ""
+               # Hold the time that this cursor was last requeried.
+               self.lastRequeryTime = 0
                # These are used to determine if the field list of successive 
select statements
                # are identical.
                self.__lastExecute = ""
@@ -436,6 +439,8 @@
                # clear mementos and new record flags:
                self._mementos = {}
                self._newRecords = {}
+               # Record the requery time for caching purposes
+               self.lastRequeryTime = time.time()
 
                if newQuery:
                        # Check for any derived fields that should not be 
included in
@@ -1151,11 +1156,12 @@
 
        def _storeData(self, data, typs):
                """Accepts a dataset and type dict from an external source and
-               uses it as its own.
+               uses it as its own. Also resets the lastRequeryTime value.
                """
                # clear mementos and new record flags:
                self._mementos = {}
                self._newRecords = {}
+               self.lastRequeryTime = time.time()
                # If None is passed as the data, exit after resetting the flags
                if data is None:
                        return




_______________________________________________
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