From 1f5b0106b34aa7c7d8714361d4fb3f6da9930b43 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Mon, 9 Oct 2023 14:56:59 +0100 Subject: [PATCH] Bug 15504: (QA follow-up) Add caching to update_lastseen This patch caches the activity triggers hash upon the first call to update_lastseen. --- Koha/Patron.pm | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index f14c1b5ce2e..062397650e2 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -1179,13 +1179,18 @@ sub update_lastseen { my ( $self, $activity ) = @_; return $self if !C4::Context->preference('TrackLastPatronActivity'); - my $tracked_activities = { - map { ( lc $_, 1 ); } split /\s*\,\s*/, - C4::Context->preference('TrackLastPatronActivityTriggers') - }; + my $cache = Koha::Caches->get_instance(); + + my $tracked_activities = $cache->get_from_cache('tracked_activities'); + if ( !$tracked_activities ) { + $tracked_activities = { + map { ( lc $_, 1 ); } split /\s*\,\s*/, + C4::Context->preference('TrackLastPatronActivityTriggers') + }; + $cache->set_in_cache( 'tracked_activities', $tracked_activities ); + } return $self unless $tracked_activities->{$activity}; - my $cache = Koha::Caches->get_instance(); my $cache_key = "track_login_" . $self->userid; my $cached = $cache->get_from_cache($cache_key); my $now = dt_from_string(); -- 2.41.0