Posts RSS Comments RSS 942 Posts and 1,831 Comments till now

Archive for September, 2007

Windy Day

I went out for a leisurely ride today. I spent more time looking at stuff and trying new routes than I usually do, and took some pictures of the things I saw.

Photographs.

TAG Speed Up

Most of TAG is fairly fast, which I am proud of, but there is one page that has been getting slower and slower as time goes on. The users page is the only page that takes a noticable amount of time to display, and it bugged me. Last night I looked at the code and it was obvious why it was slow, but I didn't have a solution. This morning when I woke up the solution was ready and waiting for me, so I coded it up at about 6:30 am.

The old code:

PHP:
  1. $sql = "SELECT id, name FROM users ORDER BY name ASC";
  2. $db->query($sql);
  3. foreach($db->record as $user) {
  4.   $sql = "SELECT count(*) FROM images WHERE user_id = ?";
  5.   $uid = $user[0];
  6.   $name = $user[1];
  7.   $db->query($sql,$uid);
  8.   $count = $db->record[0][0];
  9.   if($count> 0) {
  10.     $link = "/user/" . $uid;
  11.     $users[] = array($name,$count,$link);
  12.   }
  13. }

As you can see, the code makes a number of queries to the database equal to the number of user names in the database plus one. This is incredibly inefficient, and explains the slowness and why it was getting worse as time went on.

The new code is much simpler:

PHP:
  1. $sql = "SELECT users.id, users.name, count(images.id) FROM users, images WHERE images.user_id = users.id GROUP BY users.name, users.id ORDER BY users.name ASC";
  2. $db->query($sql);
  3. foreach($db->record as $user) {
  4.   $users[] = array($user[1],$user[2],"/user/".$user[0]);
  5. }

Now all of the aggregating and counting is done by the SQL server in a single query, rather than N+1. The page loads much faster, and is more in keeping with the speed of the rest of the site. If I make a few changes to another function I can probably get rid of the foreach as well and use the database record array directly instead.

Four in a Row

I've been out biking four days in a row now. I doubt I can keep this streak up but it is nice. On Saturday I took that "new" Schwinn out for a spin with its cannabalized Redline parts. Obvious problem is that it needs new brake pads and a longer seatpost. I'm not one of those fixed gear guys who thinks no brakes and no bar tape is cool, and the seatpost is stupidly short so I'm about an inch too low. It makes a difference after a few miles. Still, after some new parts and adjustments it should work out to be a fairly comfortable fixed ride.

On Sunday I took the Trek out for a loop around the lake. Nothing big, around 12 miles.

The last two workdays I've gotten in at 8 and taken short lunches, and skipped out at 4:30 to go riding. Yesterday was cool and dreary but there was no rain, and I tried the Highline Canal Trail west from the Cherry Creek Trail. I think it could be a fun trail to bike, but there are several road crossings and it is old beat up blacktop. My 1 inch wide tires are a little small and the ride is rough. I plan to tackle the thing again with bigger tires (more give) sometime.

Today I went the long way around the lake to the Cherry Creek Trail, and rode that up to the street crossing that has a separate bike signal (I don't remember the intersection). It was nearly 6 at that point, and the sun is setting earlier and earlier these days, so I turned around and headed home. I got to the last intersection before my apartment complex just as the sun dipped behind the buildings. Good timing I guess. Unlike yesterday it was gorgeous and sunny, and the temperature was perfect. It was a great ride.

Not sure yet what I'm going to do when winter comes and daylight savings ends. Maybe get brighter lights, maybe get a trainer. Who knows. What is certain is that getting out and rolling in the outdoors is a really nice way to spend an afternoon.

Another Bike

I decided that the Redline, as much as I like it, is just too big for me. I tried a lot of changes but nothing really made it comfortable. The culprit is the too-long top tube. I'm going to have to sell it.

I thought about adding the lights and rack that were on the Redline to the Trek, and getting another set of fenders for it (I want to sell the Redline in "stock" condition) but the darn thing is so nice and pretty I don't want to add stuff to it. I still want to have a fixed gear bike anyways.

So today on Craigslist I saw a Schwinn of similar vintage to the Trek, in the right size, for a very nice price. I went to look at it tonight and ended up buying it. It needs new tires, at least a new rear wheel, and a new chain, but is otherwise in very good shape.

Schwinn World Traveller

It's not as nice as the Trek, but that may be a good thing. The Trek 610 is so nice, with such high quality components, that I don't really want to change anything. The components on this machine are decent but nothing to get excited about.

I plan to build this into a fixed gear/single speed commuter, kind of like the Redline but the right size. To test this out, I stole the wheels and chain from the Redline and put them on. I also took off the derailers. My short test ride (it was dark) was fairly successful. This bike definitely fits better than the Redline does. It's nearly identical in size to the Trek.

I will probably get a new set of wheels and a chain for this bike, then rebuild the Redline and sell that in stock condition. We'll see where things go from there.

Real Time Slide

It's 12:45 am, MDT, and I'm watching the dollar slide in real time. At this time, the Canadian dollar is worth more than the U.S. dollar.

I for one welcome our new Northern overlords.

Stating the Obvious?

This opinion piece gets it exactly right.