From 8f816ddd4b3c29fbf6123054b0f526c3738596eb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bartek=20G=C3=B3rny?= <bartek@gorny.edu.pl>
Date: Wed, 11 Oct 2006 14:09:59 +0000
Subject: [PATCH] Changed use of caching - the previous version was really
 dumb...

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@10666 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 .../erp5_dms/DMSBaseCategoryHash.xml          | 56 ++++++++++++-------
 1 file changed, 35 insertions(+), 21 deletions(-)

diff --git a/bt5/erp5_dms/SkinTemplateItem/portal_skins/erp5_dms/DMSBaseCategoryHash.xml b/bt5/erp5_dms/SkinTemplateItem/portal_skins/erp5_dms/DMSBaseCategoryHash.xml
index b2d75045ff..ed5bd41b4c 100644
--- a/bt5/erp5_dms/SkinTemplateItem/portal_skins/erp5_dms/DMSBaseCategoryHash.xml
+++ b/bt5/erp5_dms/SkinTemplateItem/portal_skins/erp5_dms/DMSBaseCategoryHash.xml
@@ -70,30 +70,34 @@
             <key> <string>_body</string> </key>
             <value> <string>from Products.ERP5Type.Cache import CachingMethod\n
 \n
-def cached_DMSBaseCategoryHash(item_list,value_list,default_sub_field_property_dict,is_right_display):\n
-  if default_sub_field_property_dict is None:\n
-    default_sub_field_property_dict={\'field_type\': \'MultiListField\', \'item_list\': [], \'required\': 0, \'value\': [], \'is_right_display\': 0, \'key\': \'default\', \'title\': \'Categories\', \'size\': 5}\n
+def cached_DMSGetItemList(base_category):\n
+    basecatobject=context.portal_categories.resolveCategory(base_category)\n
+    return [(context.Base_trimPathName(x,100),y) for x,y in basecatobject.getCategoryChildLogicalPathItemList()]\n
 \n
-  sub_field_dict={}\n
-  maximum_list_size=5\n
+cached_DMSGetItemList=CachingMethod(cached_DMSGetItemList,id=\'DMGetItemListCachedMethodWhatever\')\n
 \n
-  default_sub_field_property_dict[\'field_type\']=\'ListField\'\n
-  default_sub_field_property_dict[\'size\']=1\n
+if default_sub_field_property_dict is None:\n
+  default_sub_field_property_dict={\'field_type\': \'MultiListField\', \'item_list\': [], \'required\': 0, \'value\': [], \'is_right_display\': 0, \'key\': \'default\', \'title\': \'Categories\', \'size\': 5}\n
 \n
-  for base_category in item_list:\n
-    if not sub_field_dict.has_key(base_category):\n
-      basecatobject=context.portal_categories.resolveCategory(base_category)\n
-      sub_field_property_dict=default_sub_field_property_dict.copy()\n
-      sub_field_property_dict[\'key\']=base_category\n
-      sub_field_property_dict[\'title\']=basecatobject.getTranslatedTitle()\n
-      sub_field_property_dict[\'item_list\']=[(context.Base_trimPathName(x,100),y) for x,y in basecatobject.getCategoryChildLogicalPathItemList()]\n
-      sub_field_property_dict[\'value\']=context.aq_parent.aq_parent.getProperty(base_category)\n
-      \n
-      sub_field_dict[base_category]=sub_field_property_dict\n
+sub_field_dict={}\n
+maximum_list_size=5\n
 \n
-  return sub_field_dict.values()\n
-cached_DMSBaseCategoryHash=CachingMethod(cached_DMSBaseCategoryHash,id=\'DMSParallelListField_DMSBaseCategoryHash\')\n
-return cached_DMSBaseCategoryHash(item_list,value_list,default_sub_field_property_dict,is_right_display)\n
+default_sub_field_property_dict[\'field_type\']=\'ListField\'\n
+default_sub_field_property_dict[\'size\']=1\n
+\n
+for base_category in item_list:\n
+  if not sub_field_dict.has_key(base_category):\n
+    basecatobject=context.portal_categories.resolveCategory(base_category)\n
+    sub_field_property_dict=default_sub_field_property_dict.copy()\n
+    sub_field_property_dict[\'key\']=base_category\n
+    sub_field_property_dict[\'title\']=basecatobject.getTranslatedTitle()\n
+    # we cache this, so that we can apply expensive path processing techniques\n
+    sub_field_property_dict[\'item_list\']=cached_DMSGetItemList(base_category)\n
+    sub_field_property_dict[\'value\']=context.aq_parent.aq_parent.getProperty(base_category)\n
+    \n
+    sub_field_dict[base_category]=sub_field_property_dict\n
+\n
+return sub_field_dict.values()\n
 \n
 \n
 # vim: syntax=python shiftwidth=2\n
@@ -145,7 +149,17 @@ return cached_DMSBaseCategoryHash(item_list,value_list,default_sub_field_propert
                             <string>is_right_display</string>
                             <string>Products.ERP5Type.Cache</string>
                             <string>CachingMethod</string>
-                            <string>cached_DMSBaseCategoryHash</string>
+                            <string>cached_DMSGetItemList</string>
+                            <string>None</string>
+                            <string>sub_field_dict</string>
+                            <string>maximum_list_size</string>
+                            <string>_write_</string>
+                            <string>_getiter_</string>
+                            <string>base_category</string>
+                            <string>_getattr_</string>
+                            <string>context</string>
+                            <string>basecatobject</string>
+                            <string>sub_field_property_dict</string>
                           </tuple>
                         </value>
                     </item>
-- 
2.30.9