Changeset 752 for trunk/cgi-bin


Ignore:
Timestamp:
06/29/15 18:24:51 (9 years ago)
Author:
Kris Deugau
Message:

/trunk

Fine-tune original allocation UPDATE; make it into a prepared statement
and call that in locations downstream instead of copy-pasting calls.
Also add missing call in targettype==leaf branch. See #8.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/cgi-bin/IPDB.pm

    r749 r752  
    22162216
    22172217    # We always update the "prime" block passed in...
    2218     $dbh->do("UPDATE allocations SET cidr = ?, type = ? WHERE id = ?", undef,
    2219         ($newblock, $args{newtype}, $prime) )
    2220         # ... but only on existing container or pool types.  Leaf -> container conversions
    2221         # may need a new parent inserted instead.
    2222         if $basetype =~ /[cm]/;
     2218    my $updsth = $dbh->prepare("UPDATE allocations SET cidr = ?, type = ? WHERE id = ?");
     2219
     2220##fixme:  There's still an edge case in the return list where some branches accidentally include
     2221# the original block as "additional".  Probably due to the ordering of when the prepared update
     2222# above gets executed.
    22232223
    22242224    # For leaf blocks, we may need to create a new parent as the "primary" instead
     
    22802280        push @retlist, { block => "$newblock", type => $disp_alloctypes{$args{newtype}}, id => $prime };
    22812281        # update the primary allocation info
    2282         $dbh->do("UPDATE allocations SET cidr = ?, type = ? WHERE id = ?", undef, ($newblock, $args{newtype}, $prime) );
     2282        $updsth->execute($newblock, $args{newtype}, $prime);
    22832283        # Reparent the free blocks in the new block
    22842284        $fbreparentsth->execute($prime, $binfo->{master_id}, $binfo->{city}, $newcontainerclass, $binfo->{vrf},
     
    23492349        } # merge peers
    23502350        # update the primary allocation info.  Do this last so we don't stomp extra data-retrieval in the loop above
    2351         $dbh->do("UPDATE allocations SET cidr = ?, type = ? WHERE id = ?", undef, ($newblock, $args{newtype}, $prime) );
     2351        $updsth->execute($newblock, $args{newtype}, $prime);
    23522352
    23532353      } # scope
     
    24042404      }
    24052405      # Update the primary allocation info.
    2406       $dbh->do("UPDATE allocations SET cidr = ?, type = ? WHERE id = ?", undef, ($newblock, $args{newtype}, $prime) );
     2406      $updsth->execute($newblock, $args{newtype}, $prime);
    24072407      # Delete any lingering free blocks
    24082408      $dbh->do("DELETE FROM freeblocks WHERE parent_id = ? AND cidr <<= ?", undef, $binfo->{parent_id}, $newblock);
     
    24162416      # keepall, mergepeer, and clearpeer all imply keeping suballocations, where leaf allocations
    24172417      # by definition do not have suballocations.
     2418      # Update the old allocation
     2419      $updsth->execute($newblock, $args{newtype}, $prime);
    24182420      # Snag the new parent info for the return list
    24192421      push @retlist, {block => "$newblock", type => $disp_alloctypes{$args{newtype}}, id => $prime};
Note: See TracChangeset for help on using the changeset viewer.