optimize SingleSession to avoid unneeded session fetches (#2536)

This commit is contained in:
Maxime Besson 2021-06-04 16:17:18 +02:00
parent 1d35a5dc84
commit 87295178e0

View File

@ -65,38 +65,50 @@ sub run {
my $moduleOptions = $self->conf->{globalStorageOptions} || {}; my $moduleOptions = $self->conf->{globalStorageOptions} || {};
$moduleOptions->{backend} = $self->conf->{globalStorage}; $moduleOptions->{backend} = $self->conf->{globalStorage};
my $sessions = $self->module->searchOn( my $singleSessionRuleMatched =
$moduleOptions, $self->singleSessionRule->( $req, $req->sessionInfo );
$self->conf->{whatToTrace}, my $singleIPRuleMatched = $self->singleIPRule->( $req, $req->sessionInfo );
$req->{sessionInfo}->{ $self->conf->{whatToTrace} } my $singleUserByIPRuleMatched =
); $self->singleUserByIPRule->( $req, $req->sessionInfo );
if ( $self->conf->{securedCookie} == 2 ) { if ( $singleSessionRuleMatched
$self->logger->debug("Looking for double sessions..."); or $singleIPRuleMatched
$linkedSessionId = $sessions->{ $req->id }->{_httpSession}; or $self->conf->{notifyOther} )
my $msg = {
$linkedSessionId my $sessions = $self->module->searchOn(
? "Linked session found -> $linkedSessionId / " . $req->id $moduleOptions,
: "NO linked session found!"; $self->conf->{whatToTrace},
$self->logger->debug($msg); $req->{sessionInfo}->{ $self->conf->{whatToTrace} }
} );
foreach my $id ( keys %$sessions ) { if ( $self->conf->{securedCookie} == 2 ) {
next if ( $req->id eq $id ); $self->logger->debug("Looking for double sessions...");
next if ( $linkedSessionId and $id eq $linkedSessionId ); $linkedSessionId = $sessions->{ $req->id }->{_httpSession};
my $session = $self->p->getApacheSession($id) or next; my $msg =
if ( $linkedSessionId
$self->singleSessionRule->( $req, $req->sessionInfo ) ? "Linked session found -> $linkedSessionId / " . $req->id
or ( $self->singleIPRule->( $req, $req->sessionInfo ) : "NO linked session found!";
and $req->{sessionInfo}->{ipAddr} ne $session->data->{ipAddr} ) $self->logger->debug($msg);
)
{
push @$deleted, $self->p->_sumUpSession( $session->data );
$self->p->_deleteSession( $req, $session, 1 );
} }
else {
push @$otherSessions, $self->p->_sumUpSession( $session->data ); foreach my $id ( keys %$sessions ) {
push @otherSessionsId, $id; next if ( $req->id eq $id );
next if ( $linkedSessionId and $id eq $linkedSessionId );
my $session = $self->p->getApacheSession($id) or next;
if (
$self->singleSessionRule->( $req, $req->sessionInfo )
or ( $self->singleIPRule->( $req, $req->sessionInfo )
and $req->{sessionInfo}->{ipAddr} ne
$session->data->{ipAddr} )
)
{
push @$deleted, $self->p->_sumUpSession( $session->data );
$self->p->_deleteSession( $req, $session, 1 );
}
else {
push @$otherSessions, $self->p->_sumUpSession( $session->data );
push @otherSessionsId, $id;
}
} }
} }
@ -106,7 +118,7 @@ sub run {
} }
) if @otherSessionsId; ) if @otherSessionsId;
if ( $self->singleUserByIPRule->( $req, $req->sessionInfo ) ) { if ($singleUserByIPRuleMatched) {
my $sessions = my $sessions =
$self->module->searchOn( $moduleOptions, 'ipAddr', $self->module->searchOn( $moduleOptions, 'ipAddr',
$req->sessionInfo->{ipAddr} ); $req->sessionInfo->{ipAddr} );