Apply session activity patch to trunk (#845)

environments/ppa-mbqj77/deployments/1
Clément Oudot 10 years ago
parent 951545de20
commit 9f689ed222
  1. 25
      lemonldap-ng-handler/lib/Lemonldap/NG/Handler/Main.pm

@ -176,13 +176,18 @@ sub fetchId {
# @return true if the session was found, false else # @return true if the session was found, false else
sub retrieveSession { sub retrieveSession {
my ( $class, $id ) = @_; my ( $class, $id ) = @_;
my $now = time();
# 1. Search if the user was the same as previous (very efficient in # 1. Search if the user was the same as previous (very efficient in
# persistent connection). # persistent connection).
return 1 if ( defined $datas->{_session_id}
if ( defined $datas->{_session_id}
and $id eq $datas->{_session_id} and $id eq $datas->{_session_id}
and ( time() - $datasUpdate < 60 ) ); and ( $now - $datasUpdate < 60 ) )
{
Lemonldap::NG::Handler::Main::Logger->lmLog(
"Get session $id from Handler internal cache", 'debug' );
return 1;
}
# 2. Get the session from cache or backend # 2. Get the session from cache or backend
$session = Lemonldap::NG::Common::Session->new( $session = Lemonldap::NG::Common::Session->new(
@ -200,10 +205,12 @@ sub retrieveSession {
$datas = $session->data; $datas = $session->data;
Lemonldap::NG::Handler::Main::Logger->lmLog( "Get session $id",
'debug' );
# Update the session to notify activity, if necessary # Update the session to notify activity, if necessary
if ( $tsv->{timeoutActivity} and ( time() - $datas->{_lastSeen} < 60 ) ) if ( $tsv->{timeoutActivity} and ( $now - $datas->{_lastSeen} > 60 ) ) {
{ $session->update( { '_lastSeen' => $now } );
$session->update( { '_lastSeen' => time } );
if ( $session->error ) { if ( $session->error ) {
Lemonldap::NG::Handler::Main::Logger->lmLog( Lemonldap::NG::Handler::Main::Logger->lmLog(
@ -211,9 +218,13 @@ sub retrieveSession {
Lemonldap::NG::Handler::Main::Logger->lmLog( $session->error, Lemonldap::NG::Handler::Main::Logger->lmLog( $session->error,
'error' ); 'error' );
} }
else {
Lemonldap::NG::Handler::Main::Logger->lmLog(
"Update _lastSeen with $now", 'debug' );
}
} }
$datasUpdate = time(); $datasUpdate = $now;
return 1; return 1;
} }
else { else {

Loading…
Cancel
Save