[Dbix-class] Close connection

Emmanuel Quevillon tuco at pasteur.fr
Tue Feb 5 14:42:18 GMT 2008


Jason Kohles wrote:
> On Jan 30, 2008, at 10:02 AM, Emmanuel Quevillon wrote:
>
>> Hi,
>>
>> I am using DBIx::Class with Catalyst under mod_perl.
>> I encouter a problem with the request I do.
>> It looks like the model create a new connection each time
>> $rs->search() is called and the connection never get closed.
>
> This is not the default behavior, so if this is happening, I would
> suspect that it's because you've done something very wrong.  But since
> you didn't include any code in your message, it's a hard thing to guess.
>
>
Hi Jason,
Thanks for your quick reply. Here is some sub code...

_do_Search_by_gene search in DB for a Particular gene name
(biology)
For each result(s) found, it calls another sub which get
journals related to it. And calls to second sub just open
connection to DB (Sybase) and stay open after Catalyst
rendered it template.

Thanks



sub _do_search_by_gene : Private {

     my($self, $c) = @_;

     my $query = $c->forward('_create_request_query', [{
'name' => $c->req->param('query') }]);

     my $geneset =
$c->model('MycoBiblioDB::Genes')->search($query,
                                                            {
....


     while(my $res = $geneset->next()){

         #Value from cookie is 0, no display for genes that
are not link to pub.
         if(!$dsp_unk){
             next if($res->get_column('reltype') =~ /^0|2$/);
         }

         unless(defined($genes->{$res->name()})){
             $genes->{$res->name()} = { };
             #Only one gene name is allowed to be search
from the query box.
             $rootgene = $res->name();
             $genes->{$res->name()}->{publications} = [ ];
             $genes->{$res->name()}->{name} = $res->name();
             $genes->{$res->name()}->{acc}  = $res->acc_num();
             $genes->{$res->name()}->{id}   = $res->id_gene();
             my $wds =
$c->forward('_build_word_color_list_from_desc',
[$res->gdesc()]);
             $genes->{$res->name()}->{desc} =
$c->forward('_highlight_from_list', [$res->gdesc(), $wds]);
         }

         #Rebuild the word list colored as we can have gene
directly linked to a publications (green)
         #and some gene that have been linked but by keyword
search. In those cases, sometime we color
         #the gene name somtime the gene description.
         if(defined($res->get_column('reltype'))){
             $words =
$c->forward('_build_word_color_list_from_desc',
[$res->get_column('reltype') > '1' ? $res->name()

            : $res->gdesc()

            ]);
         }

         if(my $pmid = $res->get_column('pmid')){

             my $a =
$c->forward('_get_publications_by_pmid', [[$pmid]])->[0];
#<===== Call to sub below...
             push @$aname, @{$a->{authors}}
if(scalar(@{$a->{authors}}));

             push @{$genes->{$res->name()}->{publications}}, {
                 id_pub   => $res->get_column('id_pub'),
                 title    => $res->get_column('title'),
                 pmid     => $res->get_column('pmid'),
                 abstract => $new_abstract ||
$res->get_column('abstract'),
                 year     => $res->get_column('year'),
                 month    => $res->get_column('month'),
                 issue    => $res->get_column('issue'),
                 volume   => $res->get_column('volume'),
                 start    => $res->get_column('pstart'),
                 end      => $res->get_column('pend'),
                 journal  => $journal,
                 authors  => $aname,
                 score    => $res->get_column('score'),
                 status   => $res->get_column('reltype'),
                 checked  => $res->get_column('checked'),
                 relvce   => $res->get_column('relevance'),
                 pgid     => $res->get_column('pgid'),
             };
         }
     }


sub _get_publications_by_pmid : Private {

     my($self, $c, $arr) = @_;

     $c->forward(qw/MycoBiblio::Controller::Root
_exitOnError/, ["Requires an array reference"])
unless(ref($arr) eq 'ARRAY');
     return unless scalar(@$arr);

     my $pub_set =
$c->model('MycoBiblioDB::Publications')->search({pmid => {
-in => $arr }},

        { join      => [

                        { 'auth_pub' => 'auth'  },

                        'pub_journal'

                       ],

          '+select' => [qw/auth.name auth.surname
pub_journal.name/],

          '+as'     => [qw/aname asurname jname/],

        }

       );
     my $pubs = { };

     while(my $pub = $pub_set->next()){

         my $pmid = $pub->pmid();
         #Create new hash structure for the new pmid.
         unless($pubs->{$pmid}){
             $pubs->{$pmid} = { };
             $pubs->{$pmid}->{authors} = [ ];
         }

         if($pub->get_columns('aname')){
             push @{$pubs->{$pmid}->{authors}}, { name =>
     $pub->get_column('aname'), surname =>
  $pub->get_column('asurname')};
         }
         #Override the same values
         $pubs->{$pmid}->{id_pub}   = $pub->id_pub();
         $pubs->{$pmid}->{title}    = $pub->title();
         $pubs->{$pmid}->{abstract} = $pub->abstract();
         $pubs->{$pmid}->{pmid}     = $pub->pmid();
         $pubs->{$pmid}->{year}     = $pub->year();
         $pubs->{$pmid}->{month}    = $pub->month();
         $pubs->{$pmid}->{volume}   = $pub->volume();
         $pubs->{$pmid}->{issue}    = $pub->issue();
         $pubs->{$pmid}->{start}    = $pub->pstart();
         $pubs->{$pmid}->{end}      = $pub->pend();
         $pubs->{$pmid}->{journal}  = $pub->get_column('jname');
     }

     my $publications = [ ];
     foreach my $p (@$arr){
         push @$publications, $pubs->{$p}
if(exists($pubs->{$p}));
     }

     return $publications;
}


-- 
-------------------------
Emmanuel Quevillon
Biological Software and Databases Group
Institut Pasteur
+33 1 44 38 95 98
tuco at_ pasteur dot fr
-------------------------






More information about the DBIx-Class mailing list