Busy Days

Well, the code refactoring went well, we got some good code done on friday. We have to re-write some stuff that has been “working” (kinda) for a while, but in the end it’s a good thing. While doing this rewrite, I discovered that nested sql queries are a bad thing. Originally my code looked something like this in pseudo-code:


select all required fields for this type
loop through required fields, record in $rec
{
select value of $rec->{field_id} from other table into $data
print “$rec->{label} : $data->{value}
}

it was sloooooow. After we imported the data and got a few hundred thousand records into the database each of the above queries was taking probably, 0.5 to 1.0 seconds. This made performance unacceptable with 70+ fields on a form.


Turning that into something that looks like this pseudo-code:


select all required fields for this type
loop through required fields, record in $rec
{
$all_record_hash{$rec->{field_id}} = { anonymous hash of other $rec data };
}

loop through data fields, record in $data
{
$data_hash{$data->{field_id}} = { value => $data->{value} };
}

then process the hashes
foreach my $field_id ( keys %all_record_hash )
{
if( $data_hash{$field_id} )
{
print “$rec->{label} : $data->{value}
} else {
print “$rec->{label} : $rec->{default_value}
}
}


Was almost instantanious. There was still about a two second period to get the value data, but the rest of the process was immediate. That query in a query just slowed things down to a halt for some reason.


I was supposed to go to the gym with the boss after work on friday, but had stuff to do so we sat and chatted a bit, then I came back home. Hung out over at Brad’s place and had a wild night of pizza, pop, a Pink Panther movie and darts beer, booze, illegal drugs and loose women. A good time.


I got home and firefly had brought fireflymom over and they proceeded to sit up till 2am searching the net for horses and a new puppie for the fireflymom. With nothing better to do (except sleep of course) I started importing all my old archives from the bygone days into movabletype. I mentioned this a while back, and it’s nice to have at least some of the past in a consistant form, with the data separated from the layout. More on this later.


Woke up this morning, had an awsome scrambled egg breakfast, hung a bit and then headed over to Jim (the car guys) place to polish up my ‘lude. I gotta admit, he’s got some mad bodywork skillz. A couple of ugly scratches are gone, others are almost gone, and the touched up area from last week is only really noticable if you know where to look. Jim’s got all the tools and skillz to make a car look shiny, and with a machine to do it it takes a lot less time than it does to polish by hand. We only did a pre-coat on it, not the full 18 step mothers treatment, but it still got polished up nicely. This means of course it will be rainy and I won’t have any evidence it looked so sexy.


Here are a few pics of how it turned out.


I did get to see exactly how pitted my hood and car was though 🙁 Guess with 117,000 km on it it’s not surprising. I still think of it as my “new car” though, which makes that hard to accept.


Going to be gone all day tomorrow, heading to visit some friends. Don’t break into my house while I’m gone, I have attack cats.