From 2c1674126233d161ba04b6ac283c0d3297dd589c Mon Sep 17 00:00:00 2001 From: nott Date: Sat, 8 Nov 2008 18:55:13 +0000 Subject: [PATCH] Make performance enhancements for lsdef cmd. git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@2479 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- perl-xCAT/xCAT/DBobjUtils.pm | 96 ++++++++++++++++++++++-------------- 1 file changed, 59 insertions(+), 37 deletions(-) diff --git a/perl-xCAT/xCAT/DBobjUtils.pm b/perl-xCAT/xCAT/DBobjUtils.pm index 380d1a84f..fff8933e0 100644 --- a/perl-xCAT/xCAT/DBobjUtils.pm +++ b/perl-xCAT/xCAT/DBobjUtils.pm @@ -157,6 +157,9 @@ sub getobjdefs my %typehash = %$hash_ref; + my @gottabs; + my %tabhash; + @::foundTableList = (); if ($::ATTRLIST eq "none") { @@ -282,51 +285,70 @@ sub getobjdefs # # Get the attr values from the DB tables # - - # if ($type eq 'node') # lookup_attr is the key to the table we are looking in if ($lookup_attr eq 'node') { + + # + # Note: there are many node attrs and they a scattered across + # many DB tables. It seems the fastest way to get a node + # def is to read each table completely the first time it + # is queried. This way we get each table only once no + # matter how many attrs or how many nodes we need. + # %tabhash holds the complete contents of each table that + # was already queried. %objhash contains only the info + # that was requested by this call to getobjdefs + # my $thistable; - my $needtocommit = 0; - if ($::gettableref{$lookup_table}) - { - # if we already opened this table use the reference - $thistable = $::gettableref{$lookup_table}; - } - else - { - # open the table - $thistable = - xCAT::Table->new( - $lookup_table, - -create => 1, - -autocommit => 0 - ); - if (!$thistable) - { - my $rsp; - $rsp->{data}->[0] = + # if we have this table + if ( grep(/^$lookup_table$/, @gottabs)) { + + # set the attr val for this object + if ($tabhash{$lookup_table}{$objname}{$attr}) { + $objhash{$objname}{$attr} = $tabhash{$lookup_table}{$objname}{$attr}; + } + } else { + # need to read new table + # open the table + $thistable = xCAT::Table->new($lookup_table, -create => 1, -autocommit => 0); + if (!$thistable) + { + my $rsp; + $rsp->{data}->[0] = "Could not get the \'$thistable\' table."; - xCAT::MsgUtils->message("E", $rsp, $::callback); - return undef; - } + xCAT::MsgUtils->message("E", $rsp, $::callback); + return undef; + } - # look up attr values - my $ent; - $ent = $thistable->getNodeAttribs($objname, [$tabattr]); + # look up attr values + my @rows = xCAT::DBobjUtils->getDBtable($lookup_table); - # create object hash $objhash{$objname}{$attr} - # - if the return is a reference and the - # attr val is defined - if (ref($ent) and defined $ent->{$tabattr}) - { - $objhash{$objname}{$attr} = $ent->{$tabattr}; - } - $thistable->commit; - } - } + # keep track that we looked up this table + push(@gottabs, $lookup_table); + + if (defined(@rows)) { + foreach my $r (@rows) { + # for each field in table/row (= attr) + foreach my $a ( keys %$r) { + # don't set the objname as an attr + if ( $a ne $lookup_attr) { + if ($r->{$a}) { + # populate the tabhash with all info + $tabhash{$lookup_table}{$r->{$lookup_attr}}{$a} = $r->{$a}; + # only want specific req in objhash + if (($r->{$lookup_attr} eq $objname) && ($a eq $tabattr)){ + $objhash{$objname}{$a}=$r->{$a}; + } + } + } + + } + } + } + $thistable->commit; + } # end - need to read new table + } # end - if the key is a node else { # look up attr values