Commit 18060ee5 authored by Antoine Catton's avatar Antoine Catton

Switch poor man list queue to optimized collections.deque

parent 98b7f177
...@@ -50,7 +50,9 @@ ...@@ -50,7 +50,9 @@
</item> </item>
<item> <item>
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string>software_instance = state_change[\'object\']\n <value> <string>import collections\n
\n
software_instance = state_change[\'object\']\n
portal = software_instance.getPortalObject()\n portal = software_instance.getPortalObject()\n
\n \n
root_hosting_subscription = portal.portal_catalog.getResultValue(uid=software_instance.SoftwareInstance_getRootHostingSubscriptionUid())\n root_hosting_subscription = portal.portal_catalog.getResultValue(uid=software_instance.SoftwareInstance_getRootHostingSubscriptionUid())\n
...@@ -59,12 +61,9 @@ root_software_instance = root_hosting_subscription.HostingSubscription_requestRo ...@@ -59,12 +61,9 @@ root_software_instance = root_hosting_subscription.HostingSubscription_requestRo
\n \n
# Use iterative algorithm instead of recursive approach in order to avoid\n # Use iterative algorithm instead of recursive approach in order to avoid\n
# complexity as much as possible.\n # complexity as much as possible.\n
flat_tree = [root_software_instance]\n flat_tree = collections.deque([root_software_instance])\n
while True:\n while flat_tree:\n
try:\n software_instance = flat_tree.popleft()\n
software_instance = flat_tree.pop(0)\n
except:\n
break\n
flat_tree.extend(software_instance.getPredecessorValueList())\n flat_tree.extend(software_instance.getPredecessorValueList())\n
try:\n try:\n
software_instance.Item_getInstancePackingListLine(service_relative_url=portal.portal_preferences.getPreferredInstanceCleanupResource())\n software_instance.Item_getInstancePackingListLine(service_relative_url=portal.portal_preferences.getPreferredInstanceCleanupResource())\n
......
...@@ -52,6 +52,8 @@ ...@@ -52,6 +52,8 @@
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string encoding="cdata"><![CDATA[ <value> <string encoding="cdata"><![CDATA[
import collections\n
\n
software_instance = state_change[\'object\']\n software_instance = state_change[\'object\']\n
portal = software_instance.getPortalObject()\n portal = software_instance.getPortalObject()\n
# Get required arguments\n # Get required arguments\n
...@@ -76,12 +78,9 @@ root_hosting_subscription = software_instance.portal_catalog.getResultValue(\n ...@@ -76,12 +78,9 @@ root_hosting_subscription = software_instance.portal_catalog.getResultValue(\n
uid=software_instance.SoftwareInstance_getRootHostingSubscriptionUid(),\n uid=software_instance.SoftwareInstance_getRootHostingSubscriptionUid(),\n
)\n )\n
\n \n
predecessor_list = root_hosting_subscription.getPredecessorValueList()\n predecessor_list = collections.deque(root_hosting_subscription.getPredecessorValueList())\n
while True:\n while predecessor_list:\n
try:\n software_instance = predecessor_list.popleft()\n
software_instance = predecessor_list.pop(0)\n
except IndexError:\n
break\n
software_instance_predecessor_list = software_instance.getPredecessorValueList() or []\n software_instance_predecessor_list = software_instance.getPredecessorValueList() or []\n
graph[software_instance.getUid()] = [predecessor.getUid()\n graph[software_instance.getUid()] = [predecessor.getUid()\n
for predecessor in software_instance_predecessor_list]\n for predecessor in software_instance_predecessor_list]\n
......
333 334
\ 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