Commit 362934b7 authored by Yoshinori Okuji's avatar Yoshinori Okuji

Cache the result of sql_catalog_schema in a volatile attribute.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@2833 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent ca97c763
...@@ -464,6 +464,9 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -464,6 +464,9 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base):
LOG('SQLCatalog Warning: could not clear catalog', 0, method_name, error=sys.exc_info()) LOG('SQLCatalog Warning: could not clear catalog', 0, method_name, error=sys.exc_info())
pass pass
# Remove the cache of catalog schema.
del self._v_catalog_schema_dict
self._clearSecurityCache() self._clearSecurityCache()
def clearReserved(self): def clearReserved(self):
...@@ -523,6 +526,26 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -523,6 +526,26 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base):
return self.sql_search_tables return self.sql_search_tables
def _getCatalogSchema(self, table=None):
catalog_schema_dict = getattr(aq_base(self), '_v_catalog_schema_dict', {})
if table not in catalog_schema_dict:
result_list = []
try:
method_name = self.sql_catalog_schema
method = getattr(self, method_name)
#LOG('_getCatalogSchema', 0, 'method_name = %r, method = %r, table = %r' % (method_name, method, table))
search_result = method(table=table)
for c in search_result:
result_list.append(c.Field)
except:
LOG('WARNING SQLCatalog._getCatalogSchema failed with the method', 0, method_name, error=sys.exc_info())
pass
catalog_schema_dict[table] = tuple(result_list)
self._v_catalog_schema_dict= catalog_schema_dict
return catalog_schema_dict[table]
def getColumnIds(self): def getColumnIds(self):
""" """
Calls the show column method and returns dictionnary of Calls the show column method and returns dictionnary of
...@@ -530,18 +553,12 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -530,18 +553,12 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base):
XXX This should be cached XXX This should be cached
""" """
method_name = self.sql_catalog_schema
keys = {} keys = {}
for table in self.getCatalogSearchTableIds(): for table in self.getCatalogSearchTableIds():
try: field_list = self._getCatalogSchema(table=table)
method = getattr(self, method_name) for field in field_list:
search_result = method(table=table) keys[field] = 1
for c in search_result: keys['%s.%s' % (table, field)] = 1 # Is this inconsistent ?
keys[c.Field] = 1
keys['%s.%s' % (table, c.Field)] = 1 # Is this inconsistent ?
except:
LOG('WARNING SQLCatalog.getColumnIds, exception with method',0,method)
pass
keys = keys.keys() keys = keys.keys()
keys.sort() keys.sort()
return keys return keys
...@@ -553,21 +570,16 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -553,21 +570,16 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base):
XXX This should be cached XXX This should be cached
""" """
method_name = self.sql_catalog_schema
keys = {} keys = {}
for table in self.getCatalogSearchTableIds(): for table in self.getCatalogSearchTableIds():
try: field_list = self._getCatalogSchema(table=table)
method = getattr(self, method_name) for field in field_list:
search_result = method(table=table) key = field
for c in search_result: if not keys.has_key(key): keys[key] = []
key = c.Field keys[key].append(table)
if not keys.has_key(key): keys[c.Field] = [] key = '%s.%s' % (table, key)
keys[key].append(table) if not keys.has_key(key): keys[key] = []
key = '%s.%s' % (table, c.Field) keys[key].append(table) # Is this inconsistent ?
if not keys.has_key(key): keys[key] = []
keys[key].append(table) # Is this inconsistent ?
except:
pass
return keys return keys
def getResultColumnIds(self): def getResultColumnIds(self):
...@@ -575,16 +587,11 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -575,16 +587,11 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base):
Calls the show column method and returns dictionnary of Calls the show column method and returns dictionnary of
Field Ids Field Ids
""" """
method_name = self.sql_catalog_schema
keys = {} keys = {}
for table in self.getCatalogSearchTableIds(): for table in self.getCatalogSearchTableIds():
try: field_list = self._getCatalogSchema(table=table)
method = getattr(self, method_name) for field in field_list:
search_result = method(table=table) keys['%s.%s' % (table, field)] = 1
for c in search_result:
keys['%s.%s' % (table, c.Field)] = 1
except:
pass
keys = keys.keys() keys = keys.keys()
keys.sort() keys.sort()
return keys return keys
...@@ -753,6 +760,7 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -753,6 +760,7 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base):
'uid' is the unique Catalog identifier for this object 'uid' is the unique Catalog identifier for this object
""" """
#LOG('catalogObject', 0, 'object = %r, path = %r' % (object, path))
if withCMF: if withCMF:
zope_root = getToolByName(self, 'portal_url').getPortalObject().aq_parent zope_root = getToolByName(self, 'portal_url').getPortalObject().aq_parent
else: else:
...@@ -1495,7 +1503,7 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -1495,7 +1503,7 @@ class Catalog(Folder, Persistent, Acquisition.Implicit, ExtensionClass.Base):
def searchResults(self, REQUEST=None, used=None, **kw): def searchResults(self, REQUEST=None, used=None, **kw):
""" Builds a complex SQL where_expression to simulate ZCalatog behaviour """ """ Builds a complex SQL where_expression to simulate ZCalatog behaviour """
""" Returns a list of brains from a set of constraints on variables """ """ Returns a list of brains from a set of constraints on variables """
# The used argument is deprecated and is ignored # The used argument is deprecated and is ignored
try: try:
# Get the search method # Get the search method
method = getattr(self, self.sql_search_results) method = getattr(self, self.sql_search_results)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment