Ignore:
Timestamp:
2018-11-06T19:26:08+13:00 (5 years 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/plugins/GreenstoneSQLPlugin.pm

    r32577 r32578  
    250250    #return undef unless $self->can_process_this_file($file); # NO, DON'T DO THIS (inherited remove_one behaviour) HERE:
    251251           # WE DON'T CARE IF IT'S AN IMAGE FILE THAT WAS DELETED.
    252            # WE CARE ABOUT REMOVING THE DOCOID OF THAT IMAGE FILE FROM THE SQL DB
     252           # WE CARE ABOUT REMOVING THE DOC_OID OF THAT IMAGE FILE FROM THE SQL DB
    253253           # SO DON'T RETURN IF CAN'T_PROCESS_THIS_FILE
    254254   
     
    430430               });
    431431
    432     # try connecting to the mysql db, if that fails it will die
     432    # try connecting to the mysql db, die if that fails
    433433    if(!$gs_sql->connect_to_db({
    434434    'db_driver' => $self->{'db_driver'},
     
    452452    # This is fatal for the plugout, let's terminate here after disconnecting again
    453453    # PrintError would already have displayed the warning message on load fail
    454     $gs_sql->disconnect_from_db()
    455         || warn("Unable to disconnect from database.\n");
     454    $gs_sql->force_disconnect_from_db();
    456455    die("Could not use db $db_name. Can't proceed.\n");
    457456    }
     
    475474    if($self->{'gs_sql'}) { # only want to work with sql db if buildcol.pl, gs_sql won't have
    476475    # a value except during buildcol, so when processor =~ m/buildproc$/.
    477     $self->{'gs_sql'}->disconnect_from_db()
    478         || warn("Unable to disconnect from database " . $self->{'site_name'} . "\n");
    479 
    480     # explicitly delete gs_sql key (setting key to undef has a different meaning from deleting)
    481     # so all future use has to make the connection again
     476    $self->{'gs_sql'}->finished();
     477
     478    # Clear gs_sql (setting key to undef has a different meaning from deleting:
     479    # undef makes key still exist but its value is unded whereas delete deletes the key)
     480    # So all future use has to make the connection again
    482481    delete $self->{'gs_sql'};
    483482    }
Note: See TracChangeset for help on using the changeset viewer.