Re: mod_perl and global %Live_Objects not being initialized

[prev] [thread] [next] [Date index for 2004/11/16]

From: Tim Bunce
Subject: Re: mod_perl and global %Live_Objects not being initialized
Date: 17:44 on 16 Nov 2004
On Tue, Nov 16, 2004 at 12:15:37PM -0500, William McKee wrote:
> 
> Hopefully Perrin will have some insight on initializing the
> %Live_Objects. I wouldn't think that it'd be the right thing to do as
> the object index would always be wiped out and thus provide none of the
> performance benefits it was meant to give.

The performance benefit is secondary to ensuring only one copy of an
object is in memory.

> > I did try these solutions, and clear_object_index ended up being the 
> > solution, when called immediately after initializing my Class::DBI 
> > object.  This is effectively the same as if Class::DBI were properly 
> > initializing the variable on its own.

This sounds like a problem that I fixed in a patch I posted around June 24.
The relevant parts for you may be:

--- Class-DBI-0.96-live_object_key/lib/Class/DBI/Relationship.pm        Sun Apr 25 16:33:36 2004
+++ Class-DBI-0.96/lib/Class/DBI/Relationship.pm        Thu Jun 24 11:24:34 2004
@@ -20,6 +20,7 @@
        my $proto = shift;
        my $name  = shift;
        my ($class, $accessor, $foreign_class, $args) = $proto->remap_arguments(@_);
+       $class->clear_object_index;
        return $proto->new({
                        name          => $name,
                        class         => $class,

--- Class-DBI-0.96-live_object_key/lib/Class/DBI.pm     Thu Jun 24 10:29:31 2004
+++ Class-DBI-0.96/lib/Class/DBI.pm     Thu Jun 24 11:57:21 2004
@@ -737,6 +748,7 @@
 sub delete {
        my $self = shift;
        return $self->_search_delete(@_) if not ref $self;
+       $self->remove_from_object_index;
        $self->call_trigger('before_delete');

        eval { $self->sql_DeleteMe->execute($self->id) };

The rest of the patch was about making retrieve() use the object index.
I've attached the patches.

Tony, what's the status of these?


> Have you tried placing that call at the end of your code? I can't see
> where it would make any difference the first time through. Have you
> tried running your code via Apache::PerlRun or mod_cgi (if it's an
> Apache::Registry script)? Does the problem still exist?
> 
> I'm not saying your solution is right or wrong; just that my experiences
> have been different. I haven't needed to explicitly clear the hash once
> I properly fixed my code.

It can be useful to edit Class::DBI to make Live_Objects a global
and then Dump the contents at the start of a request.

Tony, if you make a (development?) release/tarball available I'll
do some more basic refactoring around Live_Objects for you.

Tim.

(message missing)

Re: mod_perl and global %Live_Objects not being initialized
Tim Bunce 17:44 on 16 Nov 2004

Re: mod_perl and global %Live_Objects not being initialized
=?ISO-8859-1?Q?Ask_Bj=F8rn_Hansen?= 03:02 on 19 Nov 2004

Generated at 17:31 on 15 Feb 2005 by mariachi v0.52