1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2025-02-02 21:07:20 +01:00
vichan/tools/maintenance.php

54 lines
1.6 KiB
PHP
Raw Normal View History

2024-06-30 17:02:21 +02:00
<?php
/**
* Performs maintenance tasks. Invoke this periodically if the auto_maintenance configuration option is turned off.
*/
2024-12-11 16:34:20 +01:00
use Vichan\Data\ReportQueries;
2024-06-30 17:02:21 +02:00
require dirname(__FILE__) . '/inc/cli.php';
2024-12-11 16:34:20 +01:00
$ctx = Vichan\build_context($config);
2024-07-12 00:02:15 +02:00
echo "Clearing expired bans...\n";
2024-06-30 17:02:21 +02:00
$start = microtime(true);
$deleted_count = Bans::purge($config['require_ban_view'], $config['purge_bans']);
2024-06-30 17:02:21 +02:00
$delta = microtime(true) - $start;
2024-07-12 00:02:15 +02:00
echo "Deleted $deleted_count expired bans in $delta seconds!\n";
$time_tot = $delta;
$deleted_tot = $deleted_count;
2024-07-12 00:02:15 +02:00
echo "Clearing old antispam...\n";
$start = microtime(true);
$deleted_count = purge_old_antispam();
$delta = microtime(true) - $start;
2024-07-12 00:02:15 +02:00
echo "Deleted $deleted_count expired antispam in $delta seconds!\n";
$time_tot = $delta;
2024-12-11 16:34:20 +01:00
$deleted_tot += $deleted_count;
echo "Clearing invalid reports...\n";
$report_queries = $ctx->get(ReportQueries::class);
$start = microtime(true);
$deleted_count = $report_queries->purge();
$delta = microtime(true) - $start;
echo "Deleted $deleted_count invalid reports in $delta seconds!\n";
$time_tot += $delta;
$deleted_tot += $deleted_count;
2024-07-12 00:02:15 +02:00
if ($config['cache']['enabled'] === 'fs') {
$fs_cache = new Vichan\Data\Driver\FsCacheDriver(
$config['cache']['prefix'],
"tmp/cache/{$config['cache']['prefix']}",
'.lock',
false
);
$start = microtime(true);
$fs_cache->collect();
$delta = microtime(true) - $start;
echo "Deleted $deleted_count expired filesystem cache items in $delta seconds!\n";
$time_tot = $delta;
$deleted_tot = $deleted_count;
}
2024-07-12 00:02:15 +02:00
$time_tot = number_format((float)$time_tot, 4, '.', '');
modLog("Deleted $deleted_tot expired entries in {$time_tot}s with maintenance tool");