Show
Ignore:
Timestamp:
06.11.2018 19:26:08 (12 months ago)
Author:
ak19
Message:

Optimising. The gssql class internally has only one shared connection to the db, making the connection only the first time and disconnecting only when the last gssql is finished(). For keywords: this is implemented using the singleton coding (anti-) pattern. Now each perl process (import or buildcol) will connect to the SQL DB only once, not twice during import where it used to be once for GS SQL plugout and once for GSSQL plugin.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/plugouts/GreenstoneSQLPlugout.pm

    r32573 r32578  
    143143    my $db_params = { 
    144144    'collection_name' => $ENV{'GSDLCOLLECTION'}, 
    145     'verbosity' => 1     
     145    'verbosity' => 1 
    146146    }; 
    147147 
    148148    my $gs_sql = new gssql($db_params); 
    149149     
    150     # try connecting to the mysql db, if that fails it will die 
    151     # so don't bother preparing GreenstoneXMLPlugout by calling superclass' begin() 
     150    # try connecting to the mysql db, die if that fails 
     151    # So don't bother preparing GreenstoneXMLPlugout by calling superclass' begin() yet 
    152152    if(!$gs_sql->connect_to_db({ 
    153153    'db_driver' => $self->{'db_driver'}, 
     
    181181    # This is fatal for the plugout, let's terminate here after disconnecting again 
    182182    # PrintError would already have displayed the warning message on load fail 
    183     $gs_sql->disconnect_from_db() 
    184         || warn("Unable to disconnect from database.\n"); 
     183    $gs_sql->force_disconnect_from_db(); # disconnect_from_db() will issue a warning on error 
    185184    die("Could not use db $db_name and/or prepare its tables. Can't proceed.\n"); 
    186185    } 
     
    205204    $self->SUPER::end(@_);     
    206205     
    207     $self->{'gs_sql'}->disconnect_from_db() || warn("Unable to disconnect from database " . $self->{'site_name'} . "\n"); # disconnect_from_db() will also issue a warning, but this may be clearer 
     206    $self->{'gs_sql'}->finished(); # will disconnect from db if last instance 
     207    delete $self->{'gs_sql'}; # key gs_sql no longer exists, not just the value being undef 
    208208} 
    209209