From ad3ac5e2a3f2ba14d5fb77e2888a9585dacc9b5a Mon Sep 17 00:00:00 2001 From: Romain Courteaud <romain@nexedi.com> Date: Wed, 29 Feb 2012 16:40:50 +0100 Subject: [PATCH] Add a shared cache to speed up getComputerInformation --- .../portal_caches/slap_cache_factory.xml | 74 +++++++++++++++++++ .../persistent_cache_plugin.xml | 36 +++++++++ master/bt5/vifib_erp5/bt/revision | 2 +- master/bt5/vifib_erp5/bt/template_path_list | 2 + master/product/Vifib/Tool/SlapTool.py | 32 +++++--- 5 files changed, 133 insertions(+), 13 deletions(-) create mode 100644 master/bt5/vifib_erp5/PathTemplateItem/portal_caches/slap_cache_factory.xml create mode 100644 master/bt5/vifib_erp5/PathTemplateItem/portal_caches/slap_cache_factory/persistent_cache_plugin.xml diff --git a/master/bt5/vifib_erp5/PathTemplateItem/portal_caches/slap_cache_factory.xml b/master/bt5/vifib_erp5/PathTemplateItem/portal_caches/slap_cache_factory.xml new file mode 100644 index 000000000..d0e564adc --- /dev/null +++ b/master/bt5/vifib_erp5/PathTemplateItem/portal_caches/slap_cache_factory.xml @@ -0,0 +1,74 @@ +<?xml version="1.0"?> +<ZopeData> + <record id="1" aka="AAAAAAAAAAE="> + <pickle> + <global name="Cache Factory" module="erp5.portal_type"/> + </pickle> + <pickle> + <dictionary> + <item> + <key> <string>_count</string> </key> + <value> + <persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent> + </value> + </item> + <item> + <key> <string>_mt_index</string> </key> + <value> + <persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent> + </value> + </item> + <item> + <key> <string>_tree</string> </key> + <value> + <persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent> + </value> + </item> + <item> + <key> <string>cache_duration</string> </key> + <value> <int>200</int> </value> + </item> + <item> + <key> <string>description</string> </key> + <value> + <none/> + </value> + </item> + <item> + <key> <string>id</string> </key> + <value> <string>slap_cache_factory</string> </value> + </item> + <item> + <key> <string>portal_type</string> </key> + <value> <string>Cache Factory</string> </value> + </item> + <item> + <key> <string>title</string> </key> + <value> <string>Slap Cache Factory</string> </value> + </item> + </dictionary> + </pickle> + </record> + <record id="2" aka="AAAAAAAAAAI="> + <pickle> + <global name="Length" module="BTrees.Length"/> + </pickle> + <pickle> <int>0</int> </pickle> + </record> + <record id="3" aka="AAAAAAAAAAM="> + <pickle> + <global name="OOBTree" module="BTrees.OOBTree"/> + </pickle> + <pickle> + <none/> + </pickle> + </record> + <record id="4" aka="AAAAAAAAAAQ="> + <pickle> + <global name="OOBTree" module="BTrees.OOBTree"/> + </pickle> + <pickle> + <none/> + </pickle> + </record> +</ZopeData> diff --git a/master/bt5/vifib_erp5/PathTemplateItem/portal_caches/slap_cache_factory/persistent_cache_plugin.xml b/master/bt5/vifib_erp5/PathTemplateItem/portal_caches/slap_cache_factory/persistent_cache_plugin.xml new file mode 100644 index 000000000..60d9b2cea --- /dev/null +++ b/master/bt5/vifib_erp5/PathTemplateItem/portal_caches/slap_cache_factory/persistent_cache_plugin.xml @@ -0,0 +1,36 @@ +<?xml version="1.0"?> +<ZopeData> + <record id="1" aka="AAAAAAAAAAE="> + <pickle> + <global name="Distributed Ram Cache" module="erp5.portal_type"/> + </pickle> + <pickle> + <dictionary> + <item> + <key> <string>categories</string> </key> + <value> + <tuple> + <string>specialise/portal_memcached/persistent_memcached_plugin</string> + </tuple> + </value> + </item> + <item> + <key> <string>id</string> </key> + <value> <string>persistent_cache_plugin</string> </value> + </item> + <item> + <key> <string>int_index</string> </key> + <value> <int>0</int> </value> + </item> + <item> + <key> <string>portal_type</string> </key> + <value> <string>Distributed Ram Cache</string> </value> + </item> + <item> + <key> <string>title</string> </key> + <value> <string>Persistent Distributed Ram Cache</string> </value> + </item> + </dictionary> + </pickle> + </record> +</ZopeData> diff --git a/master/bt5/vifib_erp5/bt/revision b/master/bt5/vifib_erp5/bt/revision index 116f2e3e6..c0db21d80 100644 --- a/master/bt5/vifib_erp5/bt/revision +++ b/master/bt5/vifib_erp5/bt/revision @@ -1 +1 @@ -391 \ No newline at end of file +392 \ No newline at end of file diff --git a/master/bt5/vifib_erp5/bt/template_path_list b/master/bt5/vifib_erp5/bt/template_path_list index 013efd3a8..412c0185f 100644 --- a/master/bt5/vifib_erp5/bt/template_path_list +++ b/master/bt5/vifib_erp5/bt/template_path_list @@ -68,6 +68,8 @@ person_module/test_vifib_user_admin person_module/test_vifib_user_admin/** person_module/test_vifib_user_developer person_module/test_vifib_user_developer/** +portal_caches/slap_cache_factory +portal_caches/slap_cache_factory/persistent_cache_plugin service_module/computer_registration service_module/computer_registration/** service_module/vifib_discount diff --git a/master/product/Vifib/Tool/SlapTool.py b/master/product/Vifib/Tool/SlapTool.py index 6e353bdd6..ec861cba5 100644 --- a/master/product/Vifib/Tool/SlapTool.py +++ b/master/product/Vifib/Tool/SlapTool.py @@ -38,6 +38,7 @@ from Products.ERP5Type.Globals import InitializeClass from Products.ERP5Type.Tool.BaseTool import BaseTool from Products.ZSQLCatalog.SQLCatalog import Query, ComplexQuery from Products.ERP5Type import Permissions +from Products.ERP5Type.Cache import CachingMethod from lxml import etree try: from slapos.slap.slap import Computer @@ -140,19 +141,26 @@ class SlapTool(BaseTool): Reuses slap library for easy marshalling. """ - self.REQUEST.response.setHeader('Content-Type', 'text/xml') - slap_computer = Computer(computer_id) - parent_uid = self._getComputerUidByReference(computer_id) - slap_computer._computer_partition_list = [] - slap_computer._software_release_list = \ - self._getSoftwareReleaseValueListForComputer(computer_id) - for computer_partition in self.getPortalObject().portal_catalog( - parent_uid=parent_uid, - portal_type="Computer Partition"): - slap_computer._computer_partition_list.append( - self._getSlapPartitionByPackingList(computer_partition.getObject())) - return xml_marshaller.xml_marshaller.dumps(slap_computer) + def _getComputerInformation(computer_id, user): + self.REQUEST.response.setHeader('Content-Type', 'text/xml') + slap_computer = Computer(computer_id) + parent_uid = self._getComputerUidByReference(computer_id) + + slap_computer._computer_partition_list = [] + slap_computer._software_release_list = \ + self._getSoftwareReleaseValueListForComputer(computer_id) + for computer_partition in self.getPortalObject().portal_catalog( + parent_uid=parent_uid, + portal_type="Computer Partition"): + slap_computer._computer_partition_list.append( + self._getSlapPartitionByPackingList(computer_partition.getObject())) + return xml_marshaller.xml_marshaller.dumps(slap_computer) + + user = self.getPortalObject().portal_membership.getAuthenticatedMember().getUserName() + return CachingMethod(_getComputerInformation, + id='_getComputerInformation', + cache_factory='slap_cache_factory')(computer_id, user) security.declareProtected(Permissions.AccessContentsInformation, 'getFullComputerInformation') -- 2.30.9