Commit 7474b2b9 authored by Ayush Tiwari's avatar Ayush Tiwari

SQLCatalog: Use _getOb to get sub-objects instead of getattr

Using _getOb is always less costly than getattr, as it reduces the need to look in acquisition.
parent 4cf247ca
...@@ -961,7 +961,7 @@ class Catalog(Folder, ...@@ -961,7 +961,7 @@ class Catalog(Folder,
Clears the catalog by calling a list of methods Clears the catalog by calling a list of methods
""" """
for method_name in self.sql_clear_catalog: for method_name in self.sql_clear_catalog:
method = getattr(self, method_name) method = self._getOb(method_name)
try: try:
method() method()
except ConflictError: except ConflictError:
...@@ -989,7 +989,7 @@ class Catalog(Folder, ...@@ -989,7 +989,7 @@ class Catalog(Folder,
""" """
if self._max_uid is not None and self._max_uid() != 0: if self._max_uid is not None and self._max_uid() != 0:
method_id = self.sql_catalog_reserve_uid method_id = self.sql_catalog_reserve_uid
method = getattr(self, method_id) method = self._getOb(method_id)
self._max_uid.change(1) self._max_uid.change(1)
method(uid = [self._max_uid()]) method(uid = [self._max_uid()])
...@@ -998,7 +998,7 @@ class Catalog(Folder, ...@@ -998,7 +998,7 @@ class Catalog(Folder,
Clears reserved uids Clears reserved uids
""" """
method_id = self.sql_catalog_clear_reserved method_id = self.sql_catalog_clear_reserved
method = getattr(self, method_id) method = self._getOb(method_id)
try: try:
method() method()
except ConflictError: except ConflictError:
...@@ -1024,7 +1024,7 @@ class Catalog(Folder, ...@@ -1024,7 +1024,7 @@ class Catalog(Folder,
# It could also have a performance impact for traversals to objects in # It could also have a performance impact for traversals to objects in
# the acquisition context on Zope 2.12 even when it didn't raise a weird # the acquisition context on Zope 2.12 even when it didn't raise a weird
# error. # error.
method = getattr(self, self.sql_getitem_by_uid) method = self._getOb(self.sql_getitem_by_uid)
search_result = method(uid = uid) search_result = method(uid = uid)
if len(search_result) > 0: if len(search_result) > 0:
return search_result[0] return search_result[0]
...@@ -1217,7 +1217,7 @@ class Catalog(Folder, ...@@ -1217,7 +1217,7 @@ class Catalog(Folder,
# generator groups. # generator groups.
else: else:
method_id = self.sql_catalog_produce_reserved method_id = self.sql_catalog_produce_reserved
method = getattr(self, method_id) method = self._getOb(method_id)
# Generate an instance id randomly. Note that there is a small possibility that this # Generate an instance id randomly. Note that there is a small possibility that this
# would conflict with others. # would conflict with others.
random_factor_list = [time.time(), os.getpid(), os.times()] random_factor_list = [time.time(), os.getpid(), os.times()]
...@@ -1724,7 +1724,7 @@ class Catalog(Folder, ...@@ -1724,7 +1724,7 @@ class Catalog(Folder,
LOG('ZSQLCatalog.beforeUncatalogObject',0,'The sql_catalog_delete_uid'\ LOG('ZSQLCatalog.beforeUncatalogObject',0,'The sql_catalog_delete_uid'\
+ ' method is not defined') + ' method is not defined')
return self.uncatalogObject(path=path,uid=uid) return self.uncatalogObject(path=path,uid=uid)
method = getattr(self, method_name) method = self._getOb(method_name)
method(uid = uid) method(uid = uid)
security.declarePrivate('uncatalogObject') security.declarePrivate('uncatalogObject')
...@@ -1752,7 +1752,7 @@ class Catalog(Folder, ...@@ -1752,7 +1752,7 @@ class Catalog(Folder,
for method_name in methods: for method_name in methods:
# Do not put try/except here, it is required to raise error # Do not put try/except here, it is required to raise error
# if uncatalog does not work. # if uncatalog does not work.
method = getattr(self, method_name) method = self._getOb(method_name)
method(uid = uid) method(uid = uid)
security.declarePrivate('catalogTranslationList') security.declarePrivate('catalogTranslationList')
...@@ -1768,7 +1768,7 @@ class Catalog(Folder, ...@@ -1768,7 +1768,7 @@ class Catalog(Folder,
"""Delete translations. """Delete translations.
""" """
method_name = self.sql_delete_translation_list method_name = self.sql_delete_translation_list
method = getattr(self, method_name) method = self._getOb(method_name)
try: try:
method() method()
except ConflictError: except ConflictError:
...@@ -1779,13 +1779,13 @@ class Catalog(Folder, ...@@ -1779,13 +1779,13 @@ class Catalog(Folder,
security.declarePrivate('uniqueValuesFor') security.declarePrivate('uniqueValuesFor')
def uniqueValuesFor(self, name): def uniqueValuesFor(self, name):
""" return unique values for FieldIndex name """ """ return unique values for FieldIndex name """
method = getattr(self, self.sql_unique_values) method = self._getOb(self.sql_unique_values)
return method(column=name) return method(column=name)
security.declarePrivate('getPaths') security.declarePrivate('getPaths')
def getPaths(self): def getPaths(self):
""" Returns all object paths stored inside catalog """ """ Returns all object paths stored inside catalog """
method = getattr(self, self.sql_catalog_paths) method = self._getOb(self.sql_catalog_paths)
return method() return method()
security.declarePrivate('getUidForPath') security.declarePrivate('getUidForPath')
...@@ -1798,9 +1798,8 @@ class Catalog(Folder, ...@@ -1798,9 +1798,8 @@ class Catalog(Folder,
""" Looks up into catalog table to convert path into uid """ """ Looks up into catalog table to convert path into uid """
return { return {
x.path: x.uid x.path: x.uid
for x in getattr( for x in self._getOb(
self, self.sql_getitem_by_path
self.sql_getitem_by_path,
)( )(
path=None, path=None,
path_list=path_list, path_list=path_list,
...@@ -1813,9 +1812,8 @@ class Catalog(Folder, ...@@ -1813,9 +1812,8 @@ class Catalog(Folder,
""" Looks up into catalog table to convert uid into path """ """ Looks up into catalog table to convert uid into path """
return { return {
x.uid: x.path x.uid: x.path
for x in getattr( for x in self._getOb(
self, self.sql_getitem_by_uid
self.sql_getitem_by_uid,
)( )(
uid=None, uid=None,
uid_list=uid_list, uid_list=uid_list,
...@@ -2582,7 +2580,7 @@ class Catalog(Folder, ...@@ -2582,7 +2580,7 @@ class Catalog(Folder,
security.declarePrivate('getSearchResultsMethod') security.declarePrivate('getSearchResultsMethod')
def getSearchResultsMethod(self): def getSearchResultsMethod(self):
return getattr(self, self.sql_search_results) return self._getOb(self.sql_search_results)
security.declarePrivate('searchResults') security.declarePrivate('searchResults')
def searchResults(self, REQUEST=None, **kw): def searchResults(self, REQUEST=None, **kw):
...@@ -2602,7 +2600,7 @@ class Catalog(Folder, ...@@ -2602,7 +2600,7 @@ class Catalog(Folder,
security.declarePrivate('getCountResultsMethod') security.declarePrivate('getCountResultsMethod')
def getCountResultsMethod(self): def getCountResultsMethod(self):
return getattr(self, self.sql_count_results) return self._getOb(self.sql_count_results)
security.declarePrivate('countResults') security.declarePrivate('countResults')
def countResults(self, REQUEST=None, **kw): def countResults(self, REQUEST=None, **kw):
...@@ -2624,7 +2622,7 @@ class Catalog(Folder, ...@@ -2624,7 +2622,7 @@ class Catalog(Folder,
""" """
Record the path of an object being catalogged or uncatalogged. Record the path of an object being catalogged or uncatalogged.
""" """
method = getattr(self, self.sql_record_object_list) method = self._getOb(self.sql_record_object_list)
method(path_list=path_list, catalog=catalog) method(path_list=path_list, catalog=catalog)
security.declarePrivate('deleteRecordedObjectList') security.declarePrivate('deleteRecordedObjectList')
...@@ -2632,7 +2630,7 @@ class Catalog(Folder, ...@@ -2632,7 +2630,7 @@ class Catalog(Folder,
""" """
Delete all objects which contain any path. Delete all objects which contain any path.
""" """
method = getattr(self, self.sql_delete_recorded_object_list) method = self._getOb(self.sql_delete_recorded_object_list)
method(uid_list=uid_list) method(uid_list=uid_list)
security.declarePrivate('readRecordedObjectList') security.declarePrivate('readRecordedObjectList')
...@@ -2640,7 +2638,7 @@ class Catalog(Folder, ...@@ -2640,7 +2638,7 @@ class Catalog(Folder,
""" """
Read objects. Note that this might not return all objects since ZMySQLDA limits the max rows. Read objects. Note that this might not return all objects since ZMySQLDA limits the max rows.
""" """
method = getattr(self, self.sql_read_recorded_object_list) method = self._getOb(self.sql_read_recorded_object_list)
return method(catalog=catalog) return method(catalog=catalog)
# Filtering # Filtering
......
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