[ticket/12683] Add progress bar to delete index

PHPBB3-12683
This commit is contained in:
rubencm 2021-03-24 19:25:03 +01:00 committed by Ruben Calvo
parent 75bdbcf4fe
commit c2f3ba44bd
No known key found for this signature in database
4 changed files with 22 additions and 9 deletions

View file

@ -206,7 +206,6 @@ function get_formatted_filesize($value, $string_only = true, $allowed_units = fa
*/ */
function still_on_time($extra_time = 15) function still_on_time($extra_time = 15)
{ {
// TODO: Check the bug with this, it should be possible to restart the start time
static $max_execution_time, $start_time; static $max_execution_time, $start_time;
$current_time = microtime(true); $current_time = microtime(true);

View file

@ -86,7 +86,7 @@ class create extends command
* *
* @return int 0 if all is well, 1 if any errors occurred * @return int 0 if all is well, 1 if any errors occurred
*/ */
protected function execute(InputInterface $input, OutputInterface $output) protected function execute(InputInterface $input, OutputInterface $output): int
{ {
$io = new SymfonyStyle($input, $output); $io = new SymfonyStyle($input, $output);

View file

@ -86,10 +86,12 @@ class delete extends command
* *
* @return int 0 if all is well, 1 if any errors occurred * @return int 0 if all is well, 1 if any errors occurred
*/ */
protected function execute(InputInterface $input, OutputInterface $output) protected function execute(InputInterface $input, OutputInterface $output): int
{ {
$io = new SymfonyStyle($input, $output); $io = new SymfonyStyle($input, $output);
$io->section($this->language->lang('CLI_DESCRIPTION_SEARCHINDEX_DELETE'));
$search_backend = $input->getArgument('search-backend'); $search_backend = $input->getArgument('search-backend');
try try
@ -105,8 +107,22 @@ class delete extends command
try try
{ {
$search->delete_index($this, ''); // TODO: Read the max_post_id from db because the bucle is not always executed
$search->tidy(); $progress = $this->create_progress_bar(1, $io, $output, true);
$progress->setMessage('');
$progress->start();
$counter = 0;
while (($status = $search->delete_index($counter)) !== null)
{
$progress->setMaxSteps($status['max_post_id']);
$progress->setProgress($status['post_counter']);
$progress->setMessage(round($status['rows_per_second'], 2) . ' rows/s');
}
$progress->finish();
$io->newLine(2);
} }
catch (\Exception $e) catch (\Exception $e)
{ {

View file

@ -329,7 +329,8 @@ abstract class base implements search_backend_interface
$starttime = microtime(true); $starttime = microtime(true);
$row_count = 0; $row_count = 0;
while (still_on_time() && $post_counter <= $max_post_id) $still_on_time = PHP_SAPI === 'cli' ? true : still_on_time();
while ($still_on_time && $post_counter <= $max_post_id)
{ {
$rows = $this->get_posts_batch_after($post_counter); $rows = $this->get_posts_batch_after($post_counter);
@ -356,9 +357,6 @@ abstract class base implements search_backend_interface
} }
} }
// TODO: With cli if the previous bucle have stoped because of lack of time, launch an exception, because is an error
// cli commands should be executed in one step
// pretend the number of posts was as big as the number of ids we indexed so far // pretend the number of posts was as big as the number of ids we indexed so far
// just an estimation as it includes deleted posts // just an estimation as it includes deleted posts
$num_posts = $this->config['num_posts']; $num_posts = $this->config['num_posts'];