From 9dea705a1b7a3a3cc62105ffb0ddda9680f4819d Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Thu, 12 Jan 2012 21:19:15 +0000 Subject: [PATCH] change sub attr to be simple rel to improve efficiency of joins --- Netdisco/lib/Netdisco/DB/Result/DevicePort.pm | 31 ++++++++++--------- Netdisco/lib/Netdisco/DB/Result/DeviceVlan.pm | 26 +++++++--------- 2 files changed, 29 insertions(+), 28 deletions(-) diff --git a/Netdisco/lib/Netdisco/DB/Result/DevicePort.pm b/Netdisco/lib/Netdisco/DB/Result/DevicePort.pm index a0cd65c4..9e7b7055 100644 --- a/Netdisco/lib/Netdisco/DB/Result/DevicePort.pm +++ b/Netdisco/lib/Netdisco/DB/Result/DevicePort.pm @@ -76,24 +76,27 @@ __PACKAGE__->belongs_to( device => 'Netdisco::DB::Result::Device', 'ip', }, ); __PACKAGE__->has_many( port_vlans_tagged => 'Netdisco::DB::Result::DevicePortVlan', - sub { - my $args = shift; - return { - "$args->{foreign_alias}.ip" => { -ident => "$args->{self_alias}.ip" }, - "$args->{foreign_alias}.port" => { -ident => "$args->{self_alias}.port" }, - -not_bool => "$args->{foreign_alias}.native", - }; + { + 'foreign.ip' => 'self.ip', + 'foreign.port' => 'self.port', + }, + { + where => { -not_bool => 'me.native' }, } ); __PACKAGE__->many_to_many( tagged_vlans => 'port_vlans_tagged', 'vlan' ); +# weirdly I could not get row.tagged.vlans.count to work in TT +# so gave up and wrote this instead. +sub tagged_vlans_count { + return (shift)->tagged_vlans->count; +} __PACKAGE__->might_have( native_port_vlan => 'Netdisco::DB::Result::DevicePortVlan', - sub { - my $args = shift; - return { - "$args->{foreign_alias}.ip" => { -ident => "$args->{self_alias}.ip" }, - "$args->{foreign_alias}.port" => { -ident => "$args->{self_alias}.port" }, - -bool => "$args->{foreign_alias}.native", - }; + { + 'foreign.ip' => 'self.ip', + 'foreign.port' => 'self.port', + }, + { + where => { -bool => 'me.native' }, } ); sub native_vlan { diff --git a/Netdisco/lib/Netdisco/DB/Result/DeviceVlan.pm b/Netdisco/lib/Netdisco/DB/Result/DeviceVlan.pm index 7e065ff4..34b5c10d 100644 --- a/Netdisco/lib/Netdisco/DB/Result/DeviceVlan.pm +++ b/Netdisco/lib/Netdisco/DB/Result/DeviceVlan.pm @@ -39,23 +39,21 @@ __PACKAGE__->set_primary_key("ip", "vlan"); __PACKAGE__->belongs_to( device => 'Netdisco::DB::Result::Device', 'ip' ); __PACKAGE__->has_many( port_vlans_tagged => 'Netdisco::DB::Result::DevicePortVlan', - sub { - my $args = shift; - return { - "$args->{foreign_alias}.ip" => { -ident => "$args->{self_alias}.ip" }, - "$args->{foreign_alias}.vlan" => { -ident => "$args->{self_alias}.vlan" }, - -not_bool => "$args->{foreign_alias}.native", - }; + { + 'foreign.ip' => 'self.ip', + 'foreign.vlan' => 'self.vlan', + }, + { + where => { -not_bool => 'me.native' }, } ); __PACKAGE__->has_many( port_vlans_native => 'Netdisco::DB::Result::DevicePortVlan', - sub { - my $args = shift; - return { - "$args->{foreign_alias}.ip" => { -ident => "$args->{self_alias}.ip" }, - "$args->{foreign_alias}.vlan" => { -ident => "$args->{self_alias}.vlan" }, - -bool => "$args->{foreign_alias}.native", - }; + { + 'foreign.ip' => 'self.ip', + 'foreign.vlan' => 'self.vlan', + }, + { + where => { -bool => 'me.native' }, } ); __PACKAGE__->many_to_many( tagging_ports => 'port_vlans_tagged', 'port' );