[Commits] (twl) Query performance improvements

commits at osafoundation.org commits at osafoundation.org
Wed Aug 25 14:11:42 PDT 2004


Commit by: twl
Modified files:
chandler/parcels/osaf/contentmodel/Query.py 1.6 1.7
chandler/repository/query/Query.py 1.3 1.4

Log message:
Query performance improvements
    Don't refresh in __init__
    Handle exactKinds attribute to control recursive kind querying


ViewCVS links:
http://cvs.osafoundation.org/index.cgi/chandler/parcels/osaf/contentmodel/Query.py.diff?r1=text&tr1=1.6&r2=text&tr2=1.7
http://cvs.osafoundation.org/index.cgi/chandler/repository/query/Query.py.diff?r1=text&tr1=1.3&r2=text&tr2=1.4

Index: chandler/parcels/osaf/contentmodel/Query.py
diff -u chandler/parcels/osaf/contentmodel/Query.py:1.6 chandler/parcels/osaf/contentmodel/Query.py:1.7
--- chandler/parcels/osaf/contentmodel/Query.py:1.6	Tue Aug 24 10:48:56 2004
+++ chandler/parcels/osaf/contentmodel/Query.py	Wed Aug 25 14:11:40 2004
@@ -14,14 +14,18 @@
         self.__changed = False # transient
         self.__query = RepositoryQuery.Query(Globals.repository) # transient
         self.__query.subscribe()
-        self.onItemLoad()
+        self.__subscribe()
+
 
     def onItemLoad(self):
+        self.__subscribe()
+        log.debug("ContentQuery<%s>.onItemLoad: %s" % (self.itsUUID, self))
+        self.__refresh()
+
+    def __subscribe(self):
         events = [Globals.repository.findPath('//parcels/osaf/framework/query_changed')]
         Globals.notificationManager.Subscribe(events, self.itsUUID, self.onQueryChange)
 
-        log.debug("ContentQuery<%s>.onItemLoad: %s" % (self.itsUUID, self))
-        self.__refresh()
 
     def onItemUnload(self):
         Globals.notificationManager.Unsubscribe(self.itsUUID)
@@ -31,7 +35,7 @@
         Override of Item._fillItem
         
         @@@ this is a workaround for the fact the onItemLoad processing is done in a
-        single pass at the end, not as items are loaded.
+        single pass at the end, not as items are loaded.  this is for rehydration
         """
         super(Query, self)._fillItem(name, parent, kind, **kwds)
         # populate transients
@@ -80,6 +84,8 @@
         """
         Refresh the cached query results by executing the repository query
         """
+        if self.exactKind:
+            self.__query.recursive = False
         self.__query.execute()
         #@@@ due to generator wackiness (bad interactions with persistent list), force the query generatro to give up the whole thing
         self.results = [ i for i in self.__query ]

Index: chandler/repository/query/Query.py
diff -u chandler/repository/query/Query.py:1.3 chandler/repository/query/Query.py:1.4
--- chandler/repository/query/Query.py:1.3	Tue Aug 24 10:48:11 2004
+++ chandler/repository/query/Query.py	Wed Aug 25 14:11:41 2004
@@ -1,6 +1,6 @@
 
-__revision__  = "$Revision: 1.3 $"
-__date__      = "$Date: 2004/08/24 17:48:11 $"
+__revision__  = "$Revision: 1.4 $"
+__date__      = "$Date: 2004/08/25 21:11:41 $"
 __copyright__ = "Copyright (c) 2004 Open Source Applications Foundation"
 __license__   = "http://osafoundation.org/Chandler_0.1_license_terms.htm"
 
@@ -12,6 +12,8 @@
 log = logging.getLogger("RepoQuery")
 log.setLevel(logging.INFO)
 
+import time
+
 class Query:
 
     def __init__(self, repo, queryString = None):
@@ -39,6 +41,8 @@
         Before calling execute, be sure that they queryString
         and any parameters have been set
         """
+        
+        start = time.time()
         if self.queryString is None:
             return
         log.debug("RepoQuery.execute(): %s" % self.queryString)
@@ -55,11 +59,13 @@
         self._logical_plan = self.__analyze(self.ast)
         tools.timing.end("Analyzing query")
 #        tools.timing.results()
+        log.debug("execute: %s:%f" % (self.queryString,time.time()-start))
 
     def subscribe(self):
         """
         This query should subscribe to repository changes
         """
+        log.debug("RepoQuery<>.subscribe(): %s" % (self.queryString))
         self.__rep.addNotificationCallback(self.queryCallback)
         
     def unsubscribe(self):
@@ -81,17 +87,18 @@
         @param notification: a string containing the kind of notification
         @type notification: string
         """
+        start = time.time()
         log.debug("RepoQuery.queryCallback for %s" % self.queryString)
-        if self._logical_plan is None and self.queryString is not None:
-            self.execute()
-        elif self.queryString is None:
+        if self.queryString is None:
             return
+        elif self._logical_plan is None and self.queryString is not None:
+            self.execute()
         changed = False
         for uuid, reason, kwds in changes:
             i = self.__rep.findUUID(uuid)
             #@@@ there's a big problem with this if there are paths through multiple items -- we're going to need something fairly sophisticated here.
             if i is not None:
-                log.debug("RepoQuery.queryCallback %s:%s" % (i, i.itsKind))
+#                log.debug("RepoQuery.queryCallback %s:%s" % (i, i.itsKind))
                 if self.recursive:
                     rightKind = i.isItemOf(self._kind)
                 else:
@@ -103,9 +110,11 @@
                         action = "entered"
                     else:
                         action = "exited"
+                    break #@@@ this means we stop after 1 item (like old code) efficient, but wrong
         if changed:
             log.debug("RepoQuery.queryCallback: %s %s query result" % (uuid, action))
             self.__rep.findPath('//parcels/osaf/framework/query_changed').Post( {'query' : i.itsUUID, 'action': action} )
+        log.debug("queryCallback: %s:%f" % (self.queryString, time.time()-start))
 
     def __iter__(self):
         """
@@ -299,6 +308,7 @@
         @param plan: a tuple indicating the plan type, and a plan
         @type param: tuple 
         """
+        start = time.time()
         if plan[0] == 'for':
             return self.__execute_for(plan[1])
         elif plan[0] == 'union':
@@ -309,4 +319,4 @@
             assert False, "Difference evaluation unimplemented"
         else:
             raise ValueError, "Unrecognized plan %s" % plan[0]
-
+        log.debug("__executePlan %s:%f", (self.queryString % time.time()-start))



More information about the Commits mailing list