Performance problem solved when getting appy wrappers.

This commit is contained in:
Gaetan Delannay 2010-02-08 08:53:30 +01:00
parent f88ac2d5de
commit 0fe011e0aa
6 changed files with 25 additions and 36 deletions

View file

@ -269,7 +269,7 @@ class PloneInstaller:
nvProps.manage_changeProperties(**{'idsNotToList': current}) nvProps.manage_changeProperties(**{'idsNotToList': current})
self.tool = getattr(self.ploneSite, self.toolInstanceName) self.tool = getattr(self.ploneSite, self.toolInstanceName)
self.appyTool = self.tool._appy_getWrapper(force=True) self.appyTool = self.tool.appy()
if self.reinstall: if self.reinstall:
self.tool.createOrUpdate(False) self.tool.createOrUpdate(False)
else: else:

View file

@ -82,7 +82,7 @@ class FlavourMixin(AbstractMixin):
def getAvailablePodTemplates(self, obj, phase='main'): def getAvailablePodTemplates(self, obj, phase='main'):
'''Returns the POD templates which are available for generating a '''Returns the POD templates which are available for generating a
document from p_obj.''' document from p_obj.'''
appySelf = self._appy_getWrapper() appySelf = self.appy()
fieldName = 'podTemplatesFor%s' % obj.meta_type fieldName = 'podTemplatesFor%s' % obj.meta_type
res = [] res = []
podTemplates = getattr(appySelf, fieldName, []) podTemplates = getattr(appySelf, fieldName, [])

View file

@ -61,7 +61,7 @@ class PodTemplateMixin(AbstractMixin):
def generateDocument(self, obj): def generateDocument(self, obj):
'''Generates a document from this template, for object p_obj.''' '''Generates a document from this template, for object p_obj.'''
appySelf = self._appy_getWrapper(force=True) appySelf = self.appy()
appName = self.getProductConfig().PROJECTNAME appName = self.getProductConfig().PROJECTNAME
appModule = getattr(self.getProductConfig(), appName) appModule = getattr(self.getProductConfig(), appName)
# Temporary file where to generate the result # Temporary file where to generate the result
@ -69,7 +69,7 @@ class PodTemplateMixin(AbstractMixin):
getOsTempFolder(), obj.UID(), time.time(), self.getPodFormat()) getOsTempFolder(), obj.UID(), time.time(), self.getPodFormat())
# Define parameters to pass to the appy.pod renderer # Define parameters to pass to the appy.pod renderer
currentUser = self.portal_membership.getAuthenticatedMember() currentUser = self.portal_membership.getAuthenticatedMember()
podContext = {'self': obj._appy_getWrapper(force=True), podContext = {'self': obj.appy(),
'user': currentUser, 'user': currentUser,
'podTemplate': appySelf, 'podTemplate': appySelf,
'now': self.getProductConfig().DateTime(), 'now': self.getProductConfig().DateTime(),

View file

@ -43,7 +43,7 @@ class ToolMixin(AbstractMixin):
# It is the contextObj, not a portal type name # It is the contextObj, not a portal type name
portalTypeName = contextObjOrPortalType.portal_type portalTypeName = contextObjOrPortalType.portal_type
res = None res = None
appyTool = self._appy_getWrapper(force=True) appyTool = self.appy()
flavourNumber = None flavourNumber = None
nameElems = portalTypeName.split('_') nameElems = portalTypeName.split('_')
if len(nameElems) > 1: if len(nameElems) > 1:
@ -60,7 +60,7 @@ class ToolMixin(AbstractMixin):
# Current object is the Flavour itself. In this cas we simply # Current object is the Flavour itself. In this cas we simply
# return the wrapped contextObj. Here we are sure that # return the wrapped contextObj. Here we are sure that
# contextObjOrPortalType is an object, not a portal type. # contextObjOrPortalType is an object, not a portal type.
res = contextObjOrPortalType._appy_getWrapper(force=True) res = contextObjOrPortalType.appy()
if not res and appyTool.flavours: if not res and appyTool.flavours:
res = appyTool.flavours[0] res = appyTool.flavours[0]
# If appy=False, return the Plone object and not the Appy wrapper # If appy=False, return the Plone object and not the Appy wrapper
@ -73,7 +73,7 @@ class ToolMixin(AbstractMixin):
def getFlavoursInfo(self): def getFlavoursInfo(self):
'''Returns information about flavours.''' '''Returns information about flavours.'''
res = [] res = []
appyTool = self._appy_getWrapper(force=True) appyTool = self.appy()
for flavour in appyTool.flavours: for flavour in appyTool.flavours:
if isinstance(flavour.o, FlavourMixin): if isinstance(flavour.o, FlavourMixin):
# This is a bug: sometimes other objects are associated as # This is a bug: sometimes other objects are associated as
@ -286,7 +286,7 @@ class ToolMixin(AbstractMixin):
if 'title' in appyType['shownInfo']: if 'title' in appyType['shownInfo']:
# We may place it at another place # We may place it at another place
res = '' res = ''
appyObj = brain.getObject()._appy_getWrapper(force=True) appyObj = brain.getObject().appy()
for fieldName in appyType['shownInfo']: for fieldName in appyType['shownInfo']:
value = getattr(appyObj, fieldName) value = getattr(appyObj, fieldName)
if isinstance(value, AbstractWrapper): if isinstance(value, AbstractWrapper):

View file

@ -48,7 +48,7 @@ class AbstractMixin:
obj._appy_manageRefs(created) obj._appy_manageRefs(created)
if obj.wrapperClass: if obj.wrapperClass:
# Get the wrapper first # Get the wrapper first
appyWrapper = obj._appy_getWrapper(force=True) appyWrapper = obj.appy()
# Call the custom "onEdit" if available # Call the custom "onEdit" if available
try: try:
appyWrapper.onEdit(created) appyWrapper.onEdit(created)
@ -394,7 +394,7 @@ class AbstractMixin:
appyType = self.getAppyType(fieldName) appyType = self.getAppyType(fieldName)
tool = self.getTool() tool = self.getTool()
if self._appy_meta_type == 'flavour': if self._appy_meta_type == 'flavour':
flavour = self._appy_getWrapper(force=True) flavour = self.appy()
else: else:
portalTypeName = self._appy_getPortalType(self.REQUEST) portalTypeName = self._appy_getPortalType(self.REQUEST)
flavour = tool.getFlavour(portalTypeName) flavour = tool.getFlavour(portalTypeName)
@ -707,7 +707,7 @@ class AbstractMixin:
'''Computes on p_self the value of the Computed field corresponding to '''Computes on p_self the value of the Computed field corresponding to
p_appyType.''' p_appyType.'''
res = '' res = ''
obj = self._appy_getWrapper(force=True) obj = self.appy()
if appyType['method']: if appyType['method']:
try: try:
res = appyType['method'](obj) res = appyType['method'](obj)
@ -731,8 +731,7 @@ class AbstractMixin:
# role. # role.
res = user.has_role(transition.condition, self) res = user.has_role(transition.condition, self)
elif type(transition.condition) == types.FunctionType: elif type(transition.condition) == types.FunctionType:
obj = self._appy_getWrapper() res = transition.condition(workflow, self.appy())
res = transition.condition(workflow, obj)
elif type(transition.condition) in (tuple, list): elif type(transition.condition) in (tuple, list):
# It is a list of roles and or functions. Transition may be # It is a list of roles and or functions. Transition may be
# triggered if user has at least one of those roles and if all # triggered if user has at least one of those roles and if all
@ -745,8 +744,7 @@ class AbstractMixin:
if user.has_role(roleOrFunction, self): if user.has_role(roleOrFunction, self):
hasRole = True hasRole = True
elif type(roleOrFunction) == types.FunctionType: elif type(roleOrFunction) == types.FunctionType:
obj = self._appy_getWrapper() if not roleOrFunction(workflow, self.appy()):
if not roleOrFunction(workflow, obj):
return False return False
if hasRole != False: if hasRole != False:
res = True res = True
@ -756,7 +754,7 @@ class AbstractMixin:
'''Executes action with p_fieldName on this object.''' '''Executes action with p_fieldName on this object.'''
appyClass = self.wrapperClass.__bases__[1] appyClass = self.wrapperClass.__bases__[1]
appyType = getattr(appyClass, actionName) appyType = getattr(appyClass, actionName)
actionRes = appyType(self._appy_getWrapper(force=True)) actionRes = appyType(self.appy())
self.reindexObject() self.reindexObject()
return appyType.result, actionRes return appyType.result, actionRes
@ -805,9 +803,8 @@ class AbstractMixin:
def callAppySelect(self, selectMethod, brains): def callAppySelect(self, selectMethod, brains):
'''Selects objects from a Reference field.''' '''Selects objects from a Reference field.'''
if selectMethod: if selectMethod:
obj = self._appy_getWrapper(force=True) obj = self.appy()
allObjects = [b.getObject()._appy_getWrapper() \ allObjects = [b.getObject().appy() for b in brains]
for b in brains]
filteredObjects = selectMethod(obj, allObjects) filteredObjects = selectMethod(obj, allObjects)
filteredUids = [o.o.UID() for o in filteredObjects] filteredUids = [o.o.UID() for o in filteredObjects]
res = [] res = []
@ -876,18 +873,10 @@ class AbstractMixin:
fieldName) fieldName)
return res return res
def _appy_getWrapper(self, force=False):
'''Returns the wrapper object for p_self. It is created if it did not
exist.'''
if (not hasattr(self.aq_base, 'appyWrapper')) or force:
# In some cases (p_force=True), we need to re-generate the
# wrapper object. Else, acquisition may be lost on wrapper.o.
self.appyWrapper = self.wrapperClass(self)
return self.appyWrapper
def appy(self): def appy(self):
'''Nice alias to the previous method.''' '''Returns a wrapper object allowing to manipulate p_self the Appy
return self._appy_getWrapper(force=True) way.'''
return self.wrapperClass(self)
def _appy_getSourceClass(self, fieldName, baseClass): def _appy_getSourceClass(self, fieldName, baseClass):
'''We know that p_fieldName was defined on Python class p_baseClass or '''We know that p_fieldName was defined on Python class p_baseClass or
@ -946,7 +935,7 @@ class AbstractMixin:
objs = self.getBRefs(relName) objs = self.getBRefs(relName)
for obj in objs: for obj in objs:
if not ploneObjects: if not ploneObjects:
obj = obj._appy_getWrapper(force=True) obj = obj.appy()
res.append(obj) res.append(obj)
if res and noListIfSingleObj: if res and noListIfSingleObj:
className = self.__class__.__name__ className = self.__class__.__name__
@ -962,19 +951,19 @@ class AbstractMixin:
def _appy_showPage(self, page, pageShow): def _appy_showPage(self, page, pageShow):
'''Must I show p_page?''' '''Must I show p_page?'''
if callable(pageShow): if callable(pageShow):
return pageShow(self._appy_getWrapper(force=True)) return pageShow(self.appy())
else: return pageShow else: return pageShow
def _appy_showState(self, workflow, stateShow): def _appy_showState(self, workflow, stateShow):
'''Must I show a state whose "show value" is p_stateShow?''' '''Must I show a state whose "show value" is p_stateShow?'''
if callable(stateShow): if callable(stateShow):
return stateShow(workflow, self._appy_getWrapper()) return stateShow(workflow, self.appy())
else: return stateShow else: return stateShow
def _appy_showTransition(self, workflow, transitionShow): def _appy_showTransition(self, workflow, transitionShow):
'''Must I show a transition whose "show value" is p_transitionShow?''' '''Must I show a transition whose "show value" is p_transitionShow?'''
if callable(transitionShow): if callable(transitionShow):
return transitionShow(workflow, self._appy_getWrapper()) return transitionShow(workflow, self.appy())
else: return transitionShow else: return transitionShow
def _appy_managePermissions(self): def _appy_managePermissions(self):
@ -1205,7 +1194,7 @@ class AbstractMixin:
initiator = initiatorRes[0].getObject() initiator = initiatorRes[0].getObject()
if initiator: if initiator:
fieldName = session.get('initiatorField') fieldName = session.get('initiatorField')
initiator._appy_getWrapper(force=True).link(fieldName, self) initiator.appy().link(fieldName, self)
# Re-initialise the session # Re-initialise the session
session['initiator'] = None session['initiator'] = None

View file

@ -175,7 +175,7 @@ class AbstractWrapper:
# Create the object # Create the object
folder.invokeFactory(portalType, objId) folder.invokeFactory(portalType, objId)
ploneObj = getattr(folder, objId) ploneObj = getattr(folder, objId)
appyObj = ploneObj._appy_getWrapper(force=True) appyObj = ploneObj.appy()
# Set object attributes # Set object attributes
ploneObj._appy_manageSortedRefs() ploneObj._appy_manageSortedRefs()
for attrName, attrValue in kwargs.iteritems(): for attrName, attrValue in kwargs.iteritems():