Bugzilla – Attachment 75633 Details for
Bug 18821
TrackLastPatronActivity is a performance killer
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 18821: Convert to using cache with date checking
Bug-18821-Convert-to-using-cache-with-date-checkin.patch (text/plain), 4.77 KB, created by
Kyle M Hall (khall)
on 2018-05-29 14:07:10 UTC
(
hide
)
Description:
Bug 18821: Convert to using cache with date checking
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2018-05-29 14:07:10 UTC
Size:
4.77 KB
patch
obsolete
>From bb7e2db05f2f3c1ca490ae8ad22f64949c6c8502 Mon Sep 17 00:00:00 2001 >From: Kyle M Hall <kyle@bywatersolutions.com> >Date: Sat, 26 May 2018 06:40:24 +0000 >Subject: [PATCH] Bug 18821: Convert to using cache with date checking > >--- > C4/Auth.pm | 27 ++++++++++++++++----------- > t/db_dependent/Auth.t | 23 +++++++++-------------- > 2 files changed, 25 insertions(+), 25 deletions(-) > >diff --git a/C4/Auth.pm b/C4/Auth.pm >index 9554cd8d6e..ae2e7f6c61 100644 >--- a/C4/Auth.pm >+++ b/C4/Auth.pm >@@ -33,6 +33,7 @@ use C4::Search::History; > use Koha; > use Koha::Caches; > use Koha::AuthUtils qw(get_script_name hash_password); >+use Koha::DateUtils qw(dt_from_string); > use Koha::Library::Groups; > use Koha::Libraries; > use Koha::Patrons; >@@ -1201,7 +1202,7 @@ sub checkauth { > ); > } > >- track_login_for_session( $userid, $session ); >+ track_login_for_session( $userid ); > > return ( $userid, $cookie, $sessionID, $flags ); > } >@@ -2078,26 +2079,30 @@ sub getborrowernumber { > > =head2 track_login_for_session > >- track_login_for_session( $userid, $session ); >+ track_login_for_session( $userid ); > > C<$userid> the userid of the member >-C<$session> the CGI::Session object used to store the session's state. > > Wraps the call to $patron->track_login, the method used to update borrowers.lastseen. > > =cut > > sub track_login_for_session { >- my ( $userid, $session ) = @_; >+ my $userid = shift; >+ return unless $userid; > >- if ( $userid && $session && !$session->param('tracked_for_session') ) { >- $session->param( 'tracked_for_session', 1 ); >- $session->flush(); >+ my $patron = Koha::Patrons->find( { userid => $userid } ); >+ return unless $patron; > >- # track_login also depends on pref TrackLastPatronActivity >- my $patron = Koha::Patrons->find( { userid => $userid } ); >- $patron->track_login if $patron; >- } >+ my $cache = Koha::Caches->get_instance(); >+ my $cache_key = "seen-for-session-" . $patron->id; >+ my $cached = $cache->get_from_cache( $cache_key, { unsafe => 1 } ); >+ >+ my $today = dt_from_string()->ymd; >+ return if $cached && $cached eq $today; >+ >+ $patron->track_login; >+ $cache->set_in_cache( $cache_key, $today ); > } > > END { } # module clean-up code here (global destructor) >diff --git a/t/db_dependent/Auth.t b/t/db_dependent/Auth.t >index a9b5b17486..cfff2f7a2c 100644 >--- a/t/db_dependent/Auth.t >+++ b/t/db_dependent/Auth.t >@@ -77,38 +77,33 @@ subtest 'track_login_for_session() tests' => sub { > $patron->lastseen( undef ); > $patron->store(); > >- # Mock a CGI object with real userid param >- my $cgi = Test::MockObject->new(); >- $cgi->mock( 'param', sub { return $patron; } ); >- $cgi->mock( 'cookie', sub { return; } ); >- >- my $session = new CGI::Session( undef, undef, { Directory => File::Spec->tmpdir } ); >+ my $cache = Koha::Caches->get_instance(); >+ my $cache_key = "seen-for-session-" . $patron->id; >+ $cache->clear_from_cache($cache_key); > > t::lib::Mocks::mock_preference( 'TrackLastPatronActivity', '1' ); > >- C4::Auth::track_login_for_session( $userid ); >- $patron->_result()->discard_changes(); >- is( $patron->lastseen, undef, 'Patron last seen should be unchanged if no session is passed' ); >+ is( $patron->lastseen, undef, 'Patron should have not last seen when newly created' ); > >- C4::Auth::track_login_for_session( $userid, $session ); >+ C4::Auth::track_login_for_session( $userid ); > $patron->_result()->discard_changes(); > isnt( $patron->lastseen, undef, 'Patron should have last seen set when TrackLastPatronActivity = 1' ); > > sleep(1); # We need to wait a tiny bit to make sure the timestamp will be different > my $last_seen = $patron->lastseen; >- C4::Auth::track_login_for_session( $userid, $session ); >+ C4::Auth::track_login_for_session( $userid ); > $patron->_result()->discard_changes(); > is( $patron->lastseen, $last_seen, 'Patron last seen should be unchanged if passed the same session' ); > >- $session = new CGI::Session( undef, undef, { Directory => File::Spec->tmpdir } ); >- C4::Auth::track_login_for_session( $userid, $session ); >+ $cache->clear_from_cache($cache_key); >+ C4::Auth::track_login_for_session( $userid ); > $patron->_result()->discard_changes(); > isnt( $patron->lastseen, $last_seen, 'Patron last seen should be changed if given a new session' ); > > t::lib::Mocks::mock_preference( 'TrackLastPatronActivity', '0' ); > sleep(1); > $last_seen = $patron->lastseen; >- C4::Auth::track_login_for_session( $userid, $session ); >+ C4::Auth::track_login_for_session( $userid ); > $patron->_result()->discard_changes(); > is( $patron->lastseen, $last_seen, 'Patron should have last seen unchanged when TrackLastPatronActivity = 0' ); > >-- >2.15.1 (Apple Git-101)
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 18821
:
64425
|
64426
|
65687
|
73175
|
73706
|
73863
|
73891
|
73892
|
73893
|
75139
|
75288
|
75289
|
75427
|
75632
|
75633
|
75634
|
75635
|
75727
|
75728
|
75729
|
75733