From 49ea97e9dab54db92f8a5a5b513f027d3d4bff4e Mon Sep 17 00:00:00 2001 From: kaustubh-d Date: Mon, 24 Jun 2013 11:12:30 +0530 Subject: [PATCH] optimize deployments load. --- lib/azure/deploy.rb | 31 ++++++++++++++++++++++--------- lib/azure/host.rb | 8 ++++++++ 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/lib/azure/deploy.rb b/lib/azure/deploy.rb index 3b4d931..c99d00b 100755 --- a/lib/azure/deploy.rb +++ b/lib/azure/deploy.rb @@ -21,18 +21,31 @@ class Azure def initialize(connection) @connection=connection end - def all - deploys = Array.new - hosts = @connection.hosts.all - hosts.each do |host| - deploy = Deploy.new(@connection) - deploy.retrieve(host.name) - unless deploy.name == nil - deploys << deploy + # force_load should be true when there is something in local cache and we want to reload + # first call is always load. + def load(force_load = false) + if not @deploys || force_load + @deploys = begin + deploys = Array.new + hosts = @connection.hosts.all + hosts.each do |host| + deploy = Deploy.new(@connection) + deploy.retrieve(host.name) + if deploy.name + host.add_deploy(deploy) + deploys << deploy + end + end + deploys end end - deploys + @deploys end + + def all + self.load + end + def find(hostedservicename) deployName = nil self.all.each do |deploy| diff --git a/lib/azure/host.rb b/lib/azure/host.rb index 3bf1db3..fbc214c 100755 --- a/lib/azure/host.rb +++ b/lib/azure/host.rb @@ -80,8 +80,11 @@ class Azure attr_accessor :connection, :name, :url, :label attr_accessor :dateCreated, :description, :location attr_accessor :dateModified, :status + attr_accessor :deploys + def initialize(connection) @connection = connection + @deploys = [] end def parse(serviceXML) @name = xml_content(serviceXML, 'ServiceName') @@ -108,5 +111,10 @@ class Azure def details response = @connection.query_azure('hostedservices/' + @name + '?embed-detail=true') end + + # Deploys within this hostedservice + def add_deploy(deploy) + @deploys << deploy + end end end