Changeset 2316


Ignore:
Timestamp:
12/02/19 22:22:34 (5 years ago)
Author:
nanardon
Message:

Call post-synchro in a efficient way

This patch add callback to base allowing to web part to know when
commit() were done. Then call_sync_batch is run only when commit were
successfully done.

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Controller/Data.pm

    r2124 r2316  
    3030    my ( $self, $c ) = @_; 
    3131 
    32     $c->stash->{NoSync} = 1; 
    33  
    3432    $c->stash->{data} ||= {}; 
    3533    $c->forward('CSV'); 
  • trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Controller/Json.pm

    r2067 r2316  
    3131    my ( $self, $c ) = @_; 
    3232 
    33     $c->stash->{NoSync} = 1; 
    34  
    3533    $c->stash->{data} ||= {}; 
    3634    $c->forward($c->view('Json')); 
  • trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Controller/Login.pm

    r2069 r2316  
    2929sub index :Path :Args(0) { 
    3030    my ( $self, $c ) = @_; 
    31  
    32     $c->stash->{NoSync} = 1; 
    3331 
    3432    if ($c->req->param('username')) { 
  • trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Controller/Remote/Listing.pm

    r2066 r2316  
    5151    } 
    5252 
    53     $c->stash->{NoSync} = 1; 
    5453    $c->stash->{data} = \%objects; 
    5554} 
  • trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Controller/Remote/Search.pm

    r2068 r2316  
    2727    my $otype = $c->req->param('otype'); 
    2828    my @search = $c->req->param('q'); 
    29     $c->stash->{NoSync} = 1; 
    3029 
    3130    push(@search, 'oalias=NULL') unless($c->req->param('oalias')); 
  • trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Controller/Root.pm

    r2315 r2316  
    159159    $c->forward($c->view('TT')) unless($c->res->body); 
    160160    $c->model('Accounts')->db->rollback; 
    161     $c->model('Accounts')->call_batch_sync unless($c->stash->{NoSync}); 
     161 
     162    # DBNeedSync is set by the model when commit() is by base 
     163    if ($c->stash->{DBNeedSync}) { 
     164        $c->model('Accounts')->call_batch_sync; 
     165    } 
    162166} 
    163167 
  • trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Controller/Stat.pm

    r2066 r2316  
    2525    my ( $self, $c ) = @_; 
    2626 
    27     $c->stash->{NoSync} = 1; 
    2827} 
    2928 
  • trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Model/Accounts.pm

    r2169 r2316  
    5151    $self->{_default_base} and return $self->{_default_base}; 
    5252    $self->{_default_base} = $self->base; 
     53    $self->{_default_base}->SetCallBack( 
     54        'commit', 
     55        sub { $self->{c}->stash->{DBNeedSync} = 1; } 
     56    ); 
    5357    $self->{_default_base}->load or return; 
    5458    $self->{_default_base}->wexported(1); 
     
    205209    my ($self) = @_; 
    206210 
     211    $self->{c}->log->debug('Running call_batch_sync()'); 
     212 
    207213    if (my $command = $self->{c}->config->{callSyncCmd}) { 
    208214        if (system($command) != 0) { 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases.pm

    r2282 r2316  
    6060    $base->{_la} = $options->{la}; 
    6161 
     62    # Callback, the list bellow give the supported callback 
     63    $base->{_cb} = $options->{cb} || { 
     64        commit => undef, 
     65        postcommit => undef, 
     66    }; 
     67 
    6268    $base->SetConnectedUser($ENV{LA_USERNAME}) if ($ENV{LA_USERNAME}); 
    6369 
    6470    la_log(LA_DEBUG, 'Instanciate base %s (%s)', ($base->label || 'N/A'), $pclass); 
    6571    $base 
     72} 
     73 
     74=head2 SetCallBack( $cb, $code ) 
     75 
     76Set callbalc $<cb> to function C<$code>. 
     77 
     78=cut 
     79 
     80sub SetCallBack { 
     81    my ( $self, $cb, $code ) = @_; 
     82 
     83    if (exists ($self->{_cb}{$cb})) { 
     84        return $self->{_cb}{$cb} = $code; 
     85    } 
     86} 
     87 
     88=head2 GetCallBack( $cb ) 
     89 
     90Set callback $<cb> to function C<$code>. 
     91 
     92=cut 
     93 
     94sub GetCallBack { 
     95    my ( $self, $cb ) = @_; 
     96 
     97    if (exists ($self->{_cb}{$cb})) { 
     98        $self->{_cb}{$cb} || sub { 1; }; 
     99    } 
    66100} 
    67101 
     
    879913    } 
    880914 
     915    $self->GetCallBack('commit')->(); 
     916 
    881917    $self->postcommit(); 
    882918 
     
    902938            } 
    903939        ); 
     940        $self->GetCallBack('postcommit')->(); 
    904941    } else { 
    905942        return 1; 
Note: See TracChangeset for help on using the changeset viewer.