mirror of
				https://github.com/xcat2/xcat-core.git
				synced 2025-11-04 05:12:30 +00:00 
			
		
		
		
	Optimize the performance for getNodesAttribs and getAllNodeAttribs (#3593)
				
					
				
			As `get_site_attribute` subroutine could not cache the value for hierarchicalattrs configuration, this commit move the check logic of `hierarchicalattrs` from `getNodeAttribs_nosub_returnany` to `getNodesAttribs` and `getAllNodeAttribs` to optimize the the performance of bulk query. After testing, this change will bring 50% performance improvement for `getNodesAttribs` subroutine.
This commit is contained in:
		@@ -2186,6 +2186,12 @@ sub getNodesAttribs {
 | 
			
		||||
        $self->{nodelist}->{_use_cache} = 1;
 | 
			
		||||
    }
 | 
			
		||||
    my $rethash;
 | 
			
		||||
    my @hierarchy_attrs = ();
 | 
			
		||||
    my $hierarchy_field = xCAT::TableUtils->get_site_attribute("hierarchicalattrs");
 | 
			
		||||
    if ($hierarchy_field) {
 | 
			
		||||
        @hierarchy_attrs = split(/,/, $hierarchy_field);
 | 
			
		||||
    }
 | 
			
		||||
    $options{hierarchy_attrs} = \@hierarchy_attrs;
 | 
			
		||||
    foreach (@$nodelist) {
 | 
			
		||||
        my @nodeentries = $self->getNodeAttribs($_, \@realattribs, %options);
 | 
			
		||||
        $rethash->{$_} = \@nodeentries;    #$self->getNodeAttribs($_,\@attribs);
 | 
			
		||||
@@ -2435,6 +2441,16 @@ sub getNodeAttribs
 | 
			
		||||
    } else {
 | 
			
		||||
        @attribs = @_;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (!exists($options{hierarchy_attrs})) {
 | 
			
		||||
        my @hierarchy_attrs = ();
 | 
			
		||||
        my $hierarchy_field = xCAT::TableUtils->get_site_attribute("hierarchicalattrs");
 | 
			
		||||
        if ($hierarchy_field) {
 | 
			
		||||
            @hierarchy_attrs = split(/,/, $hierarchy_field);
 | 
			
		||||
        }
 | 
			
		||||
        $options{hierarchy_attrs} = \@hierarchy_attrs;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    my $datum;
 | 
			
		||||
    my $oldusecache;
 | 
			
		||||
    my $nloldusecache;
 | 
			
		||||
@@ -2665,12 +2681,7 @@ sub getNodeAttribs_nosub_returnany
 | 
			
		||||
 | 
			
		||||
    my $attrib;
 | 
			
		||||
    my $result;
 | 
			
		||||
    my @hierarchy_attrs;
 | 
			
		||||
    my $hierarchy_field = xCAT::TableUtils->get_site_attribute("hierarchicalattrs");
 | 
			
		||||
    if ($hierarchy_field) {
 | 
			
		||||
        @hierarchy_attrs = split(/,/, $hierarchy_field);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    my @hierarchy_attrs = @{ $options{hierarchy_attrs} };
 | 
			
		||||
    my $data = $results[0];
 | 
			
		||||
    if (defined {$data}) { #if there was some data for the node, loop through and check it
 | 
			
		||||
        foreach $result (@results) {
 | 
			
		||||
@@ -3103,7 +3114,13 @@ sub getAllNodeAttribs
 | 
			
		||||
            #}  end SF 3580
 | 
			
		||||
 | 
			
		||||
            #my $localhash = $self->getNodesAttribs(\@nodes,$attribq); #NOTE:  This is stupid, rebuilds the cache for every entry, FIXME
 | 
			
		||||
 | 
			
		||||
            my %options;
 | 
			
		||||
            my @hierarchy_attrs = ();
 | 
			
		||||
            my $hierarchy_field = xCAT::TableUtils->get_site_attribute("hierarchicalattrs");
 | 
			
		||||
            if ($hierarchy_field) {
 | 
			
		||||
                @hierarchy_attrs = split(/,/, $hierarchy_field);
 | 
			
		||||
            }
 | 
			
		||||
            $options{hierarchy_attrs} = \@hierarchy_attrs;
 | 
			
		||||
            foreach (@nodes)
 | 
			
		||||
            {
 | 
			
		||||
                if ($donenodes{$_}) { next; }
 | 
			
		||||
@@ -3117,7 +3134,7 @@ sub getAllNodeAttribs
 | 
			
		||||
                #  }
 | 
			
		||||
                #} else {
 | 
			
		||||
                my @attrs =
 | 
			
		||||
                  $self->getNodeAttribs($_, $attribq); #@{$localhash->{$_}} #$self->getNodeAttribs($_, $attribq)
 | 
			
		||||
                  $self->getNodeAttribs($_, $attribq, %options); #@{$localhash->{$_}} #$self->getNodeAttribs($_, $attribq)
 | 
			
		||||
                ;    #Logic moves to getNodeAttribs
 | 
			
		||||
                     #}
 | 
			
		||||
                 #populate node attribute by default, this sort of expansion essentially requires it.
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user