View | Details | Raw Unified | Return to bug 34027
Collapse All | Expand All

(-)a/misc/cronjobs/cleanup_database.pl (-2 / +22 lines)
Lines 30-35 use constant DEFAULT_DEBARMENTS_PURGEDAYS => 30; Link Here
30
use constant DEFAULT_JOBS_PURGEDAYS               => 1;
30
use constant DEFAULT_JOBS_PURGEDAYS               => 1;
31
use constant DEFAULT_JOBS_PURGETYPES              => qw{ update_elastic_index };
31
use constant DEFAULT_JOBS_PURGETYPES              => qw{ update_elastic_index };
32
use constant DEFAULT_EDIFACT_MSG_PURGEDAYS        => 365;
32
use constant DEFAULT_EDIFACT_MSG_PURGEDAYS        => 365;
33
use constant DEFAULT_LOGS_BATCHSIZE               => 1000;
33
34
34
use Getopt::Long qw( GetOptions );
35
use Getopt::Long qw( GetOptions );
35
36
Lines 87-92 Usage: $0 [-h|--help] [--confirm] [--sessions] [--sessdays DAYS] [-v|--verbose] Link Here
87
   --log-action       Specify which action log action entries to trim. Repeatable.
88
   --log-action       Specify which action log action entries to trim. Repeatable.
88
   --logs DAYS        purge entries from action_logs older than DAYS days.
89
   --logs DAYS        purge entries from action_logs older than DAYS days.
89
                      Defaults to 180 days if no days specified.
90
                      Defaults to 180 days if no days specified.
91
   --logs-batch ROWS  Delete action_logs rows in batches of ROWS. Ignored if --logs is not set.
92
                      Defaults to 1000.
90
   --searchhistory DAYS  purge entries from search_history older than DAYS days.
93
   --searchhistory DAYS  purge entries from search_history older than DAYS days.
91
                         Defaults to 30 days if no days specified
94
                         Defaults to 30 days if no days specified
92
   --list-invites  DAYS  purge (unaccepted) list share invites older than DAYS days.
95
   --list-invites  DAYS  purge (unaccepted) list share invites older than DAYS days.
Lines 171-176 my $jobs_days; Link Here
171
my @jobs_types;
174
my @jobs_types;
172
my $reports;
175
my $reports;
173
my $edifact_msg_days;
176
my $edifact_msg_days;
177
my $logs_batch;
174
178
175
my $command_line_options = join( " ", @ARGV );
179
my $command_line_options = join( " ", @ARGV );
176
180
Lines 218-223 GetOptions( Link Here
218
    'jobs-days:i'                => \$jobs_days,
222
    'jobs-days:i'                => \$jobs_days,
219
    'reports:i'                  => \$reports,
223
    'reports:i'                  => \$reports,
220
    'edifact-messages:i'         => \$edifact_msg_days,
224
    'edifact-messages:i'         => \$edifact_msg_days,
225
    'logs-batch:i'               => \$logs_batch,
221
) || usage(1);
226
) || usage(1);
222
227
223
# Use default values
228
# Use default values
Lines 232-237 $pMessages = DEFAULT_MESSAGES_PURGEDAYS if defined($pMessages) Link Here
232
$jobs_days        = DEFAULT_JOBS_PURGEDAYS          if defined($jobs_days)        && $jobs_days == 0;
237
$jobs_days        = DEFAULT_JOBS_PURGEDAYS          if defined($jobs_days)        && $jobs_days == 0;
233
@jobs_types       = (DEFAULT_JOBS_PURGETYPES)       if $jobs_days                 && @jobs_types == 0;
238
@jobs_types       = (DEFAULT_JOBS_PURGETYPES)       if $jobs_days                 && @jobs_types == 0;
234
$edifact_msg_days = DEFAULT_EDIFACT_MSG_PURGEDAYS   if defined($edifact_msg_days) && $edifact_msg_days == 0;
239
$edifact_msg_days = DEFAULT_EDIFACT_MSG_PURGEDAYS   if defined($edifact_msg_days) && $edifact_msg_days == 0;
240
$logs_batch       = DEFAULT_LOGS_BATCHSIZE          if defined($logs_batch)       && $logs_batch == 0;
235
241
236
# Choose the number of days at which to purge unaccepted list invites:
242
# Choose the number of days at which to purge unaccepted list invites:
237
# - DAYS defined in the list-invites parameter is prioritised first
243
# - DAYS defined in the list-invites parameter is prioritised first
Lines 408-416 if ($pLogs) { Link Here
408
        $log_query .= " AND action IN (" . join( ',', ('?') x @log_actions ) . ")";
414
        $log_query .= " AND action IN (" . join( ',', ('?') x @log_actions ) . ")";
409
        push @query_params, @log_actions;
415
        push @query_params, @log_actions;
410
    }
416
    }
417
    if ($logs_batch) {
418
        $log_query .= " LIMIT ?";
419
        push @query_params, $logs_batch;
420
    }
411
    $sth = $dbh->prepare($log_query);
421
    $sth = $dbh->prepare($log_query);
412
    if ($confirm) {
422
    if ($confirm) {
413
        $sth->execute( $pLogs, @query_params ) or die $dbh->errstr;
423
        if ($logs_batch) {
424
            my $counter = 0;
425
            my $rows    = 0;
426
            while ( $counter <= $rows ) {
427
                $sth->execute( $pLogs, @query_params ) or die $dbh->errstr;
428
                sleep 3;
429
                $rows    += $sth->rows;
430
                $counter += $logs_batch;
431
            }
432
        } else {
433
            $sth->execute( $pLogs, @query_params ) or die $dbh->errstr;
434
        }
414
    }
435
    }
415
    print "Done with purging action_logs.\n" if $verbose;
436
    print "Done with purging action_logs.\n" if $verbose;
416
}
437
}
417
- 

Return to bug 34027