Class-DBI - Improving performance

Posted on Thu Aug 31 17:45:29 2006 by szabgab
Improving performance

Some of the pages of CPAN::Forum take as much as 5-15 seconds to load.
I added the following line to the cgi script to see what's going on.

BEGIN { $ENV{DBI_TRACE}='1=/tmp/dbitrace.log'; }

After some digging in the output I see a single page view can generate 10s of queries. especially those that show a full thread. The one I checked generated 48 queries.

By adding all the fields of tha posts table to the Essential columns, I could elimnate the repeated query of the post table for each entry. That brought me down to 30 queries.

__PACKAGE__->columns(Essential => qw/id gid uid parent subject text date thread hidden/);

The problem is that for each entry I call $post->id->username and each such call generates another request to the database.
How could I tell CDBI to load the username field from the users table as well while fetching the posts?

Write a response