From 7be677403f30d17bfe7beb77dd35c518275c50d5 Mon Sep 17 00:00:00 2001 From: Shawn Catanzarite Date: Mon, 23 Sep 2013 12:43:20 -0700 Subject: [PATCH] speed things up for get calls. add find_by_name filter. still needs some refactoring --- lib/fog/dynect/models/dns/records.rb | 55 +++++++++++++++++++++++----- 1 file changed, 46 insertions(+), 9 deletions(-) diff --git a/lib/fog/dynect/models/dns/records.rb b/lib/fog/dynect/models/dns/records.rb index 87c81e7d0..9b7527d09 100644 --- a/lib/fog/dynect/models/dns/records.rb +++ b/lib/fog/dynect/models/dns/records.rb @@ -17,6 +17,51 @@ module Fog service.get_all_records(zone.domain, options).body['data'].each do |url| (_, _, t, _, fqdn, id) = url.split('/') type = t.gsub(/Record$/, '') + + # leave out the default, read only records + # by putting this here we don't make the secondary request for these records + next if ['NS', 'SOA'].include?(type) + + record = service.get_record(type, zone.domain, fqdn, 'record_id' => id).body['data'] + + data << { + :identity => record['record_id'], + :fqdn => record['fqdn'], + :type => record['record_type'], + :rdata => record['rdata'] + } + end + + load(data) + end + + def get(record_id) + requires :zone + + list = service.get_all_records(zone.domain, options).body['data'] + url = list.detect { |e| e =~ /\/#{record_id}$/ } + (_, _, t, _, fqdn, id) = url.split('/') + type = t.gsub(/Record$/, '') + record = service.get_record(type, zone.domain, fqdn, 'record_id' => id).body['data'] + + new({ + :identity => record['record_id'], + :fqdn => record['fqdn'], + :type => record['record_type'], + :rdata => record['rdata'] + }) + end + + def find_by_name(name) + requires :zone + data = [] + service.get_all_records(zone.domain, options).body['data'].select{|url| url =~ /\/#{name}\//}.each do |url| + (_, _, t, _, fqdn, id) = url.split('/') + type = t.gsub(/Record$/, '') + + # leave out the default, read only records + next if ['NS', 'SOA'].include?(type) + record = service.get_record(type, zone.domain, fqdn, 'record_id' => id).body['data'] data << { @@ -27,20 +72,12 @@ module Fog } end - # leave out the default, read only records - data = data.reject {|record| ['NS', 'SOA'].include?(record[:type])} - load(data) end - def get(record_id) - # FIXME: can this be done more efficiently? - all.detect {|record| record.identity == record_id} - end - def new(attributes = {}) requires :zone - super({ :zone => zone }.merge!(attributes)) + super({:zone => zone}.merge!(attributes)) end end