deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michal Fojtik <mfoj...@redhat.com>
Subject Re: [PATCH core 2/3] Fix Mock driver speed in case you have a lot of YAML files
Date Wed, 03 Nov 2010 13:48:30 GMT
On 03/11/10 14:46 +0100, mfojtik@redhat.com wrote:
>From: Michal Fojtik <mfojtik@redhat.com>
>
>---
> server/lib/deltacloud/drivers/mock/mock_driver.rb |   13 ++++++++++++-
> 1 files changed, 12 insertions(+), 1 deletions(-)
>
>diff --git a/server/lib/deltacloud/drivers/mock/mock_driver.rb b/server/lib/deltacloud/drivers/mock/mock_driver.rb
>index 847319b..52c63b7 100644
>--- a/server/lib/deltacloud/drivers/mock/mock_driver.rb
>+++ b/server/lib/deltacloud/drivers/mock/mock_driver.rb
>@@ -130,12 +130,23 @@ class MockDriver < Deltacloud::BaseDriver
>   #
>   # Instances
>   #
>+  require 'ruby-prof'

^^ Please ignore this line, it will be removed before push ;-)
>
>+
>+  def instance(credentials, opts={})
>+    check_credentials( credentials )
>+    instance_filename = File.join(@storage_root, 'instances', "#{opts[:id]}.yml")
>+    return nil unless File.exists?(instance_filename)
>+    instance = YAML::load_file(instance_filename)
>+    instance[:actions] = instance_actions_for( instance[:state] )
>+    instance[:id] = File::basename(instance_filename, ".yml")
>+    Instance.new(instance)
>+  end
> 
>   def instances(credentials, opts=nil)
>     check_credentials( credentials )
>     instances = []
>     Dir[ "#{@storage_root}/instances/*.yml" ].each do |instance_file|
>-      instance = YAML.load( File.read( instance_file ) )
>+      instance = YAML::load_file(instance_file)
>       if ( instance[:owner_id] == credentials.user )
>         instance[:id] = File.basename( instance_file, ".yml" )
>         instance[:actions] = instance_actions_for( instance[:state] )
>-- 
>1.7.2.3
>

-- 
--------------------------------------------------------
Michal Fojtik, mfojtik@redhat.com
Deltacloud API: http://deltacloud.org
--------------------------------------------------------

Mime
View raw message