Use cached nameservers in zonefile procedure

This commit is contained in:
Martin Lensment 2014-11-26 15:05:10 +02:00
parent e695a6e628
commit b58417cbee
2 changed files with 21 additions and 22 deletions

View file

@ -52,25 +52,17 @@ class AddZonefileProcedure < ActiveRecord::Migration
chr(10) chr(10)
) INTO ns_records; ) INTO ns_records;
-- use caching
/*SELECT concat(cns.hostname, '. IN A ', cns.ipv4, '.') FROM cached_nameservers cns WHERE EXISTS (
SELECT 1
FROM nameservers ns
JOIN domains d ON d.id = ns.domain_id
WHERE d.name LIKE include_filter AND d.name NOT LIKE exclude_filter
AND ns.hostname = cns.hostname AND ns.ipv4 = cns.ipv4 AND ns.ipv6 = cns.ipv6
AND ns.ipv4 IS NOT NULL AND ns.ipv4 <> ''
);*/
-- a records -- a records
SELECT array_to_string( SELECT array_to_string(
array( array(
SELECT concat(ns.hostname, '. IN A ', ns.ipv4, '.') SELECT concat(cns.hostname, '. IN A ', cns.ipv4, '.') FROM cached_nameservers cns WHERE EXISTS (
FROM domains d SELECT 1
JOIN nameservers ns ON ns.domain_id = d.id FROM nameservers ns
WHERE d.name LIKE include_filter AND d.name NOT LIKE exclude_filter JOIN domains d ON d.id = ns.domain_id
AND ns.ipv4 IS NOT NULL AND ns.ipv4 <> '' WHERE d.name LIKE include_filter AND d.name NOT LIKE exclude_filter
AND ns.hostname = cns.hostname AND ns.ipv4 = cns.ipv4 AND ns.ipv6 = cns.ipv6
AND ns.ipv4 IS NOT NULL AND ns.ipv4 <> ''
)
), ),
chr(10) chr(10)
) INTO a_records; ) INTO a_records;
@ -78,11 +70,14 @@ class AddZonefileProcedure < ActiveRecord::Migration
-- aaaa records -- aaaa records
SELECT array_to_string( SELECT array_to_string(
array( array(
SELECT concat(ns.hostname, '. IN AAAA ', ns.ipv6, '.') SELECT concat(cns.hostname, '. IN AAAA ', cns.ipv6, '.') FROM cached_nameservers cns WHERE EXISTS (
FROM domains d SELECT 1
JOIN nameservers ns ON ns.domain_id = d.id FROM nameservers ns
WHERE d.name LIKE include_filter AND d.name NOT LIKE exclude_filter JOIN domains d ON d.id = ns.domain_id
AND ns.ipv6 IS NOT NULL AND ns.ipv6 <> '' WHERE d.name LIKE include_filter AND d.name NOT LIKE exclude_filter
AND ns.hostname = cns.hostname AND ns.ipv6 = cns.ipv6 AND ns.ipv6 = cns.ipv6
AND ns.ipv6 IS NOT NULL AND ns.ipv6 <> ''
)
), ),
chr(10) chr(10)
) INTO a4_records; ) INTO a4_records;

View file

@ -1,5 +1,5 @@
class CreateNameserversCache < ActiveRecord::Migration class CreateNameserversCache < ActiveRecord::Migration
def change def up
create_table :cached_nameservers, id: false do |t| create_table :cached_nameservers, id: false do |t|
t.string :hostname t.string :hostname
t.string :ipv4 t.string :ipv4
@ -13,4 +13,8 @@ class CreateNameserversCache < ActiveRecord::Migration
); );
SQL SQL
end end
def down
drop_table :cached_nameservers
end
end end