Changeset 1911 for trunk


Ignore:
Timestamp:
01/04/17 12:16:26 (7 years ago)
Author:
nanardon
Message:

Speed up attribute registration checks

Location:
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql.pm

    r1910 r1911  
    9898        $self->log(LA_DEBUG, 'New connection to DB'); 
    9999 
     100 
    100101        foreach my $otype ($self->list_supported_objects) { 
     102            my %attrlist = map { $_ => 1 } $self->list_registered_attributes($otype); 
    101103            foreach my $attribute ($self->list_canonical_fields($otype, 'r')) { 
    102104                my $attr = $self->attribute($otype, $attribute); 
     
    104106                $attr->{managed} and next; 
    105107 
    106                 if ($self->is_registered_attribute($otype, $attribute)) { 
     108                if ($attrlist{$attribute}) { 
    107109                } else { 
    108110                    if($self->register_attribute($otype, $attribute, $attr->{comment})) { 
     
    778780} 
    779781 
     782=head2 list_registered_attributes ($otype) 
     783 
     784List all regiestered attribute 
     785 
     786=cut 
     787 
     788sub list_registered_attributes { 
     789    my ($self, $otype) = @_; 
     790    my $pclass = $self->_load_obj_class($otype) or return; 
     791    if ($pclass->_has_extended_attributes) { 
     792        return $pclass->list_registered_attributes($self); 
     793    } else { 
     794        return (); 
     795    } 
     796} 
     797 
    780798=head2 get_attribute_comment ($otype, $attribute) 
    781799 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/objects.pm

    r1910 r1911  
    12241224} 
    12251225 
     1226=head2 list_registered_attributes 
     1227 
     1228Return the list for all registered attribute 
     1229 
     1230=cut 
     1231 
     1232sub list_registered_attributes { 
     1233    my ($class, $base) = @_; 
     1234 
     1235    my $sth = $base->db->prepare( 
     1236        sprintf(q{ 
     1237            select canonical from %s 
     1238            }, $class->_attributes_table 
     1239        ) 
     1240    ); 
     1241    $sth->execute(); 
     1242    my @attrs = (); 
     1243 
     1244    while (my $res = $sth->fetchrow_hashref) { 
     1245        push(@attrs, $res->{canonical}); 
     1246    } 
     1247    return @attrs; 
     1248} 
     1249 
     1250 
    12261251=head2 get_attribute_comment $base, $attribute) 
    12271252 
Note: See TracChangeset for help on using the changeset viewer.