[Dbix-class] Strange overwriting of values from db query

kakimoto at tpg.com.au kakimoto at tpg.com.au
Thu Jun 25 06:54:07 GMT 2009


hi guys,

 I have a very weird problem here.
 I make 3 db search calls to a method, _get_entries_from_db and store
each of the results in different hash slices of $lists{'active_list'},
$lists{'expired_list'} and $lists{'inactive_list'}.

 The weirdness occurs when I notice that the values in the hash slices
change after each run of the method , _get_entries_from_db even if I did
not write to them!

 Here's the output
===============

[debug]  _get_entries_from_db - 7 entries pulled
[debug]  _get_entries_from_db - 7 entries pulled
[debug]  _get_entries_from_db - 68 entries pulled
[debug]  _get_entries_from_db - 68 entries pulled
[debug]  _get_entries_from_db - 4 entries pulled
[debug]  _get_entries_from_db - 4 entries pulled
[debug] R has 4
 f has 4
j has 4
[debug] INACTIVE LIST -  inactive List has 4 entries
[debug] INACTIVE LIST -  expired List has 4 entries
[debug] INACTIVE LIST -  Active List has 4 entries
[debug]  Outside, active_list has 4
[debug]  Outside, inactive_list has 4
[debug]  Outside, expired_list has 4
[debug]  Retrieved current user's subscriptions.
[debug] Rendering template "agents/subscriptions/manage.tt2"
[info] Request took 0.259641s (3.851/s)



Here are the codes:
=============


sub _get_entries_from_db
{
    my ($self, $c, $user_subscriptions_filters) = @_;

    my $user_subscriptions =
$c->model('gozilaDB::UserSubscriptions')->search(
        $user_subscriptions_filters,
        {
            # join with the Subscriptions database table( identified via
            # the accessor/relationship name, subscription.
            q{join}     => q{subscription},
            q{prefetch} => q{subscription},
        },
    );

    $c->log->debug(" _get_entries_from_db - " .
$user_subscriptions->count. " entries pulled" );
    return $user_subscriptions;
}




sub get_user_subscriptions
{
    my ( $self, $c, $args ) = @_;

    my %user_subscriptions_filter = (
        q{user_id} =>
gozila::Controller::Shared->get_current_active_user($c),
    );

   my %extra_clause = (
        q{join} => q{subscription},
        # prefetch data from the subscriptions database table too
    );

    if (defined($args->{'id'}))
    {
        $user_subscriptions_filter{'me.id'} = $args->{'id'};
    }

    $c->log->debug( " _get_user_subscriptions -> Retrieving with args of "
          . Data::Dumper->Dump( [\%user_subscriptions_filter] ) );

    my %lists = ();
    # get active entries
    $user_subscriptions_filter{'active_to'} = { '>=', 'NOW()'};
    $lists{'active_list'} = $self->_get_entries_from_db($c,
\%user_subscriptions_filter);
    my $r = $self->_get_entries_from_db($c, \%user_subscriptions_filter);

    # get expired entries
    $user_subscriptions_filter{'active_to'} = { '<', 'NOW()'};
    $lists{'expired_list'} = $self->_get_entries_from_db($c,
\%user_subscriptions_filter);
    my $f =$self->_get_entries_from_db($c, \%user_subscriptions_filter);

    # get inactive entries - waiting for activation
    $user_subscriptions_filter{'active_to'} = { '=', undef };
    $lists{'inactive_list'} = $self->_get_entries_from_db($c,
\%user_subscriptions_filter);
    my $j =$self->_get_entries_from_db($c, \%user_subscriptions_filter);

    $c->log->debug("R has ". $r->count . "\n f has ".  $f->count ."\nj
has ". $j->count );
    $c->log->debug("INACTIVE LIST -  inactive List has " .
$lists{'inactive_list'}->count . " entries ");
    $c->log->debug("INACTIVE LIST -  expired List has " .
$lists{'expired_list'}->count . " entries ");
    $c->log->debug("INACTIVE LIST -  Active List has " .
$lists{'active_list'}->count . " entries ");

    return \%lists;
}




thank you :)

K. akimoto



More information about the DBIx-Class mailing list