Bugzilla – Attachment 186360 Details for
Bug 34027
Add functionality to cleanup_database.pl to purge action logs in batches
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 34027: (follow-up) Make sleep seconds a command-line param
Bug-34027-follow-up-Make-sleep-seconds-a-command-l.patch (text/plain), 5.07 KB, created by
Aleisha Amohia
on 2025-09-11 02:29:48 UTC
(
hide
)
Description:
Bug 34027: (follow-up) Make sleep seconds a command-line param
Filename:
MIME Type:
Creator:
Aleisha Amohia
Created:
2025-09-11 02:29:48 UTC
Size:
5.07 KB
patch
obsolete
>From 1cc35cdbf6fbfe161f75f84861576279e4378b25 Mon Sep 17 00:00:00 2001 >From: Aleisha Amohia <aleisha@catalyst.net.nz> >Date: Tue, 8 Oct 2024 02:20:12 +0000 >Subject: [PATCH] Bug 34027: (follow-up) Make sleep seconds a command-line > param > >Use --logs-sleep SECONDS to specify how many seconds Koha should wait between batches when deleting action logs. > >Defaults to 3 > >Sponsored-by: Auckland University of Technology >Sponsored-by: Catalyst IT > >Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> >--- > misc/cronjobs/cleanup_database.pl | 11 ++++++++--- > 1 file changed, 8 insertions(+), 3 deletions(-) > >diff --git a/misc/cronjobs/cleanup_database.pl b/misc/cronjobs/cleanup_database.pl >index 3bf4a3bb0be..456f73a74e7 100755 >--- a/misc/cronjobs/cleanup_database.pl >+++ b/misc/cronjobs/cleanup_database.pl >@@ -31,6 +31,7 @@ use constant DEFAULT_JOBS_PURGEDAYS => 1; > use constant DEFAULT_JOBS_PURGETYPES => qw{ update_elastic_index }; > use constant DEFAULT_EDIFACT_MSG_PURGEDAYS => 365; > use constant DEFAULT_LOGS_BATCHSIZE => 1000; >+use constant DEFAULT_LOGS_BATCHSLEEP => 3; > > use Getopt::Long qw( GetOptions ); > use Try::Tiny; >@@ -60,7 +61,7 @@ use Koha::UploadedFiles; > > sub usage { > print STDERR <<USAGE; >-Usage: $0 [-h|--help] [--confirm] [--sessions] [--sessdays DAYS] [-v|--verbose] [--zebraqueue DAYS] [-m|--mail] [--merged] [--import DAYS] [--logs DAYS] [--searchhistory DAYS] [--restrictions DAYS] [--all-restrictions] [--fees DAYS] [--temp-uploads] [--temp-uploads-days DAYS] [--uploads-missing 0|1 ] [--statistics DAYS] [--statistics-type TYPE] [--deleted-catalog DAYS] [--deleted-patrons DAYS] [--old-issues DAYS] [--old-reserves DAYS] [--transfers DAYS] [--labels DAYS] [--cards DAYS] [--bg-days DAYS [--bg-type TYPE] ] [--edifact-messages DAYS] >+Usage: $0 [-h|--help] [--confirm] [--sessions] [--sessdays DAYS] [-v|--verbose] [--zebraqueue DAYS] [-m|--mail] [--merged] [--import DAYS] [--logs DAYS] [--logs-batch ROWS] [--logs-sleep SECS] [--searchhistory DAYS] [--restrictions DAYS] [--all-restrictions] [--fees DAYS] [--temp-uploads] [--temp-uploads-days DAYS] [--uploads-missing 0|1 ] [--statistics DAYS] [--statistics-type TYPE] [--deleted-catalog DAYS] [--deleted-patrons DAYS] [--old-issues DAYS] [--old-reserves DAYS] [--transfers DAYS] [--labels DAYS] [--cards DAYS] [--bg-days DAYS [--bg-type TYPE] ] [--edifact-messages DAYS] > > -h --help prints this help message, and exits, ignoring all > other options >@@ -92,6 +93,7 @@ Usage: $0 [-h|--help] [--confirm] [--sessions] [--sessdays DAYS] [-v|--verbose] > Defaults to 180 days if no days specified. > --logs-batch ROWS Delete action_logs rows in batches of ROWS. Ignored if --logs is not set. > Defaults to 1000. >+ --logs-sleep SECS Sleeps for SECS seconds between each batch of action_logs rows deleted. Defaults to 3. > --searchhistory DAYS purge entries from search_history older than DAYS days. > Defaults to 30 days if no days specified > --list-invites DAYS purge (unaccepted) list share invites older than DAYS days. >@@ -182,6 +184,7 @@ my @jobs_types; > my $reports; > my $edifact_msg_days; > my $logs_batch; >+my $logs_sleep = 3; > > my $command_line_options = join( " ", @ARGV ); > cronlogaction( { info => $command_line_options } ); >@@ -233,6 +236,7 @@ GetOptions( > 'reports:i' => \$reports, > 'edifact-messages:i' => \$edifact_msg_days, > 'logs-batch:i' => \$logs_batch, >+ 'logs-sleep:i' => \$logs_sleep, > ) || usage(1); > > # Use default values >@@ -248,6 +252,7 @@ $jobs_days = DEFAULT_JOBS_PURGEDAYS if defined($jobs_days) > @jobs_types = (DEFAULT_JOBS_PURGETYPES) if $jobs_days && @jobs_types == 0; > $edifact_msg_days = DEFAULT_EDIFACT_MSG_PURGEDAYS if defined($edifact_msg_days) && $edifact_msg_days == 0; > $logs_batch = DEFAULT_LOGS_BATCHSIZE if defined($logs_batch) && $logs_batch == 0; >+$logs_sleep = DEFAULT_LOGS_BATCHSLEEP if defined($logs_sleep) && $logs_sleep == 0; > > @statistics_types = ( @statistics_types, @Koha::Statistic::pseudonymization_types ) if defined($statistics_type_pseudo); > @statistics_types = keys %{ { map { $_, 1 } @statistics_types } }; # remove duplicate types >@@ -408,7 +413,7 @@ if ($pZ3950) { > > if ($pLogs) { > print "Purging records from action_logs.\n" if $verbose; >- for (0..10000){ >+ for ( 0 .. 10000 ) { > $dbh->do(q{ INSERT INTO action_logs (user,timestamp) VALUES (52,"2022-01-01 09:00:00") }); > $dbh->do(q{ UPDATE action_logs SET timestamp = "2020-01-01 10:00:00" ORDER BY action_id DESC LIMIT 1 }); > } >@@ -440,7 +445,7 @@ if ($pLogs) { > do { > $sth->execute(@query_params) or die $dbh->errstr; > $rows_deleted = $sth->rows; >- sleep 3; # Adjust sleep time as needed >+ sleep $logs_sleep; > } while ( $rows_deleted == $logs_batch ); > } else { > $sth->execute(@query_params) or die $dbh->errstr; >-- >2.39.5
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 34027
:
152394
|
152395
|
167407
|
167408
|
167412
|
167413
|
167414
|
172506
|
172543
|
172544
|
172545
|
172546
|
172547
|
186357
|
186358
|
186359
| 186360