From: Chris W. <la...@us...> - 2004-11-27 22:57:19
|
Update of /cvsroot/openinteract/OpenInteract2/lib/OpenInteract2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19847 Modified Files: SessionManager.pm Log Message: explicitly ->delete() sessions with no relevant data so we don't get a bunch of empty sessions Index: SessionManager.pm =================================================================== RCS file: /cvsroot/openinteract/OpenInteract2/lib/OpenInteract2/SessionManager.pm,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** SessionManager.pm 18 Feb 2004 05:25:26 -0000 1.7 --- SessionManager.pm 27 Nov 2004 22:56:51 -0000 1.8 *************** *** 29,33 **** }; if ( $@ ) { ! $log->warn( "Error fetching session with ID [$session_id]: $@\n", "Continuing..." ); OpenInteract2::Cookie->expire( SESSION_COOKIE ); --- 29,33 ---- }; if ( $@ ) { ! $log->warn( "Error fetching session with ID '$session_id': $@\n", "Continuing..." ); OpenInteract2::Cookie->expire( SESSION_COOKIE ); *************** *** 86,125 **** my ( $class, $session ) = @_; $log ||= get_logger( LOG_SESSION ); ! return 1 unless ( ref $session ); if ( tied %{ $session } ) { ! my %useful_session_keys = map { $_ => 1 } keys %{ $session }; ! delete $useful_session_keys{_session_id}; ! delete $useful_session_keys{is_new}; ! if ( ref $session->{_oi_cache} and ! scalar keys %{ $session->{_oi_cache} } == 0 ) { ! delete $useful_session_keys{_oi_cache}; ! } ! if ( scalar keys %useful_session_keys > 0 ) { ! my $is_new = $session->{is_new}; ! delete $session->{is_new}; ! $class->_save_session( $session, $is_new ); ! } ! else { ! $log->is_debug && ! $log->debug( "Tied session found, not saving since ", ! "it doesn't have useful info" ); ! } } elsif ( ref $session eq 'HASH' ) { ! return 1 unless ( scalar keys %{ $session } ); ! $log->is_info && ! $log->info( "Create new session with data from hashref" ); ! my $new_session = $class->_create_session; ! if ( $new_session ) { ! foreach my $key ( keys %{ $session } ) { ! $new_session->{ $key } = $session->{ $key }; ! } ! $class->_save_session( $new_session, 1 ); ! } ! else { ! $log->error( "No value returned from _create_session; ", ! "this shouldn't happen..." ); ! } } else { --- 86,100 ---- my ( $class, $session ) = @_; $log ||= get_logger( LOG_SESSION ); ! ! unless ( ref $session ) { ! $log->is_info && $log->info( "No session found, not storing" ); ! return 1; ! } if ( tied %{ $session } ) { ! $class->_store_tied_session( $session ); } elsif ( ref $session eq 'HASH' ) { ! $class->_store_hashref_session( $session ); } else { *************** *** 130,134 **** --- 105,154 ---- } + sub _store_tied_session { + my ( $class, $session ) = @_; + my %useful_session_keys = map { $_ => 1 } keys %{ $session }; + delete $useful_session_keys{_session_id}; + delete $useful_session_keys{is_new}; + if ( ref $session->{_oi_cache} and + scalar keys %{ $session->{_oi_cache} } == 0 ) { + delete $useful_session_keys{_oi_cache}; + } + if ( scalar keys %useful_session_keys > 0 ) { + $log->is_info && + $log->info( "Storing tied session because of useful keys: ", + join( ', ', keys %useful_session_keys ) ); + my $is_new = $session->{is_new}; + delete $session->{is_new}; + $class->_save_session( $session, $is_new ); + } + else { + $log->is_debug && + $log->debug( "Tied session, no useful info; removing..." ); + tied( %{ $session } )->delete(); + } + } + sub _store_hashref_session { + my ( $class, $session ) = @_; + unless ( scalar keys %{ $session } ) { + $log->is_debug && + $log->debug( "Hashref session, no useful info; not storing..." ); + return 1; + } + $log->is_info && + $log->info( "Create new session with data from hashref using ", + "keys: ", keys %{ $session } ); + my $new_session = $class->_create_session; + if ( $new_session ) { + foreach my $key ( keys %{ $session } ) { + $new_session->{ $key } = $session->{ $key }; + } + $class->_save_session( $new_session, 1 ); + } + else { + $log->error( "No value returned from _create_session; ", + "this shouldn't happen..." ); + } + } sub _save_session { *************** *** 150,154 **** if ( $is_new ) { $log->is_info && ! $log->info( "Sending cookie for new session" ); OpenInteract2::Cookie->create( { name => SESSION_COOKIE, --- 170,175 ---- if ( $is_new ) { $log->is_info && ! $log->info( "Sending cookie for new session; cookie should ", ! "expire in: ", $expiration ); OpenInteract2::Cookie->create( { name => SESSION_COOKIE, |