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