From 8431ef249e586b08e9c4ac24709ccda0c8e3b44e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Fri, 13 May 2011 13:24:44 +0200 Subject: [PATCH] Session nur einmal pro Request speichern, und zwar danach. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Vorher wurde die Session mindestens zweimal vor dem Request gespechert. Unnötig. --- SL/Auth.pm | 42 +++++++++++------------------------------- 1 file changed, 11 insertions(+), 31 deletions(-) diff --git a/SL/Auth.pm b/SL/Auth.pm index 78b12e16c..fca3b8b2c 100644 --- a/SL/Auth.pm +++ b/SL/Auth.pm @@ -598,37 +598,7 @@ sub _create_session_id { } sub create_or_refresh_session { - $main::lxdebug->enter_sub(); - - my $self = shift; - - $session_id ||= $self->_create_session_id(); - - my ($form, $dbh, $query, $sth, $id); - - $form = $main::form; - $dbh = $self->dbconnect(); - - $dbh->begin_work; - do_query($::form, $dbh, qq|LOCK auth.session_content|); - - $query = qq|SELECT id FROM auth.session WHERE id = ?|; - - ($id) = selectrow_query($form, $dbh, $query, $session_id); - - if ($id) { - do_query($form, $dbh, qq|UPDATE auth.session SET mtime = now() WHERE id = ?|, $session_id); - - } else { - do_query($form, $dbh, qq|INSERT INTO auth.session (id, ip_address, mtime) VALUES (?, ?, now())|, $session_id, $ENV{REMOTE_ADDR}); - - } - - $self->save_session($dbh); - - $dbh->commit(); - - $main::lxdebug->leave_sub(); + $session_id ||= shift->_create_session_id; } sub save_session { @@ -645,6 +615,16 @@ sub save_session { do_query($::form, $dbh, qq|LOCK auth.session_content|); do_query($::form, $dbh, qq|DELETE FROM auth.session_content WHERE session_id = ?|, $session_id); + my $query = qq|SELECT id FROM auth.session WHERE id = ?|; + + my ($id) = selectrow_query($::form, $dbh, $query, $session_id); + + if ($id) { + do_query($::form, $dbh, qq|UPDATE auth.session SET mtime = now() WHERE id = ?|, $session_id); + } else { + do_query($::form, $dbh, qq|INSERT INTO auth.session (id, ip_address, mtime) VALUES (?, ?, now())|, $session_id, $ENV{REMOTE_ADDR}); + } + if (%{ $self->{SESSION} }) { my $query = qq|INSERT INTO auth.session_content (session_id, sess_key, sess_value) VALUES (?, ?, ?)|; my $sth = prepare_query($::form, $dbh, $query); -- 2.20.1