Accidental coding victories

posted by Jeff | Sunday, August 24, 2008, 11:00 PM | comments: 0

It's a double-edged sword when you find something in your code that wasn't quite right and you fix it. On one hand, you uncover a potential problem and deal with it, but on the other hand, you wonder if you've got other brittle things going on.

Tonight I was coding a one-off data item that gets cached for five minutes at a time. When I fired up the debugger to see that it was in there, I noticed that there were dozens of entries in the cache. That seemed odd. So I looked to see what some of them were, and it was a bunch of forum post collections, cached by topic.

It turns out that they were being cached when called up to be indexed by the forum search engine. Topic objects have a GetPosts() method, that, not surprisingly, gets the posts from that topic. The data layer caches these by default. So my test database, filled with a bunch of CoasterBuzz posts from 2002 or something, was being indexed in the background.

The truth is that this bug is pretty low impact. Few forums need to be indexed from the start unless they're being migrated, and since the app doesn't run in the wild very much, that pretty much means only CoasterBuzz when it does get upgraded. But the problem is that these giant cached pieces might bump out a bunch of smaller ones that are more useful, like user data, and that's not desirable. So I did a little Ctrl-Alt-M to extract the method sans caching, and in two seconds I had it all worked out.

After all the years of mucking around in that code, it's funny how I'd write it differently, yet again, if I started over. I can promise you that a rewrite of that ain't gonna happen any time soon!


Comments

No comments yet.


Post your comment: