Commit 4feff2ad authored by Romain Courteaud's avatar Romain Courteaud

Speed up computer cache calculation.

parent b88dce16
from Products.ERP5Type.UnrestrictedMethod import UnrestrictedMethod
from AccessControl.SecurityManagement import getSecurityManager, \
setSecurityManager, newSecurityManager
@UnrestrictedMethod
def getComputerReference(item):
portal_type = item.getPortalType()
computer = None
if portal_type == 'Software Installation':
computer = item.getAggregateValue(portal_type='Computer')
elif portal_type == 'Computer Partition':
computer = item.getParentValue()
elif portal_type in ['Software Instance', 'Slave Instance']:
partition = item.getAggregateValue(portal_type='Computer Partition')
if partition is not None:
computer = partition.getParentValue()
if computer is not None and computer.getValidationState() == 'validated':
return computer.getReference()
return None
def Item_activateFillComputerInformationCache(state_change):
item = state_change['object']
portal = item.getPortalObject()
computer_reference = getComputerReference(item)
if computer_reference is None:
return None
sm = getSecurityManager()
try:
newSecurityManager(None,
portal.acl_users.getUserById(computer_reference))
portal.portal_slap._activateFillComputerInformationCache(
computer_reference, computer_reference)
finally:
setSecurityManager(sm)
<workflow_chain>
<chain>
<type>Computer Partition</type>
<workflow>slapos_slap_tool_interaction_workflow</workflow>
</chain>
<chain>
<type>Slave Instance</type>
<workflow>slapos_slap_tool_interaction_workflow</workflow>
</chain>
<chain>
<type>Software Installation</type>
<workflow>slapos_slap_tool_interaction_workflow</workflow>
</chain>
<chain>
<type>Software Instance</type>
<workflow>slapos_slap_tool_interaction_workflow</workflow>
</chain>
</workflow_chain>
\ No newline at end of file
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="InteractionWorkflowDefinition" module="Products.ERP5.InteractionWorkflow"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_objects</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>creation_guard</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>groups</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>slapos_slap_tool_interaction_workflow</string> </value>
</item>
<item>
<key> <string>manager_bypass</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>SlapOS Slap Tool Interaction Workflow</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Interaction" module="Products.ERP5.Interaction"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_mapping</string> </key>
<value>
<dictionary/>
</value>
</item>
<item>
<key> <string>_objects</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>interactions</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Scripts" module="Products.DCWorkflow.Scripts"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_mapping</string> </key>
<value>
<dictionary/>
</value>
</item>
<item>
<key> <string>_objects</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>scripts</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
</item> </item>
<item> <item>
<key> <string>_module</string> </key> <key> <string>_module</string> </key>
<value> <string>VifibUtil</string> </value> <value> <string>SlapOSSlapTool</string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Variables" module="Products.DCWorkflow.Variables"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_mapping</string> </key>
<value>
<dictionary/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>variables</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Worklists" module="Products.DCWorkflow.Worklists"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_mapping</string> </key>
<value>
<dictionary/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>worklists</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
9 10
\ No newline at end of file \ No newline at end of file
SlapOSSlapTool
\ No newline at end of file
Computer Partition | slapos_slap_tool_interaction_workflow
Slave Instance | slapos_slap_tool_interaction_workflow
Software Installation | slapos_slap_tool_interaction_workflow
Software Instance | slapos_slap_tool_interaction_workflow
\ No newline at end of file
slapos_slap_tool_interaction_workflow
\ No newline at end of file
import hashlib import hashlib
from Products.ERP5Type.UnrestrictedMethod import UnrestrictedMethod
from AccessControl.SecurityManagement import getSecurityManager, \
setSecurityManager, newSecurityManager
def getSha512Hexdiest(s): def getSha512Hexdiest(s):
return hashlib.sha512(s).hexdigest() return hashlib.sha512(s).hexdigest()
@UnrestrictedMethod
def getComputerReference(item):
portal_type = item.getPortalType()
computer = None
if portal_type == 'Software Installation':
computer = item.getAggregateValue(portal_type='Computer')
elif portal_type == 'Computer Partition':
computer = item.getParentValue()
elif portal_type in ['Software Instance', 'Slave Instance']:
partition = item.getAggregateValue(portal_type='Computer Partition')
if partition is not None:
computer = partition.getParentValue()
if computer is not None and computer.getValidationState() == 'validated':
return computer.getReference()
return None
def Item_activateFillComputerInformationCache(state_change):
item = state_change['object']
portal = item.getPortalObject()
computer_reference = getComputerReference(item)
if computer_reference is None:
return None
sm = getSecurityManager()
try:
newSecurityManager(None,
portal.acl_users.getUserById(computer_reference))
portal.portal_slap._activateFillComputerInformationCache(
computer_reference, computer_reference)
finally:
setSecurityManager(sm)
865 866
\ No newline at end of file \ No newline at end of file
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