wp-rocket icon indicating copy to clipboard operation
wp-rocket copied to clipboard

Table `wp_wpr_rocket_cache` doesn't exist when running WP-CLI cronjobs

Open simkoG opened this issue 2 years ago • 4 comments

Before submitting an issue please check that you’ve completed the following steps:

  • Made sure you’re on the latest version ✅
  • Used the search feature to ensure that the bug hasn’t been reported before ✅

Describe the bug There is an error message in the log file when WP cron is called via WP-CLI.

WordPress adatbázis hiba Table 'wp_wpr_rocket_cache' doesn't exist a lekérdezésben SELECT id FROM `wp_wpr_rocket_cache` WHERE `last_accessed` <= date_sub(now(), interval 1 month) készítette include('phar:///home/***username***/wp-cli.phar/php/boot-phar.php'), include('phar:///home/***username***/wp-cli.phar/vendor/wp-cli/wp-cli/php/wp-cli.php'), WP_CLI\bootstrap, WP_CLI\Bootstrap\LaunchRunner->process, WP_CLI\Runner->start, WP_CLI\Runner->run_command_and_exit, WP_CLI\Runner->run_command, WP_CLI\Dispatcher\Subcommand->invoke, call_user_func, WP_CLI\Dispatcher\CommandFactory::WP_CLI\Dispatcher\{closure}, call_user_func, Cron_Event_Command->run, Cron_Event_Command::run_event, do_action_ref_array('rocket_preload_clean_rows_time_event'), WP_Hook->do_action, WP_Hook->apply_filters, WP_Rocket\Engine\Preload\Cron\Subscriber->remove_old_rows, WP_Rocket\Engine\Preload\Database\Queries\Cache->remove_all_not_accessed_rows, WP_Rocket\Engine\Preload\Database\Queries\Cache->get_old_cache

The log's language is Hungarian. Translation: "WordPress database error Table wp_wpr_rocket_cache doesn't exist on database"

The mentioned table exists in the database as you can see in the image.

image

To Reproduce Steps to reproduce the behavior:

  1. Install the latest WordPress / WP Rocket.
  2. Disable the WP-Cron: define( 'DISABLE_WP_CRON' , true );
  3. Install the latest WP-CLI.
  4. Call the cron events with the wp cron event run --due-now command.
  5. See the error log.

Expected behavior No database error when running WP-CLI cronjobs.

Backlog Grooming (for WP Media dev team use only)

  • [ ] Reproduce the problem
  • [ ] Identify the root cause
  • [ ] Scope a solution
  • [ ] Estimate the effort

simkoG avatar Aug 29 '22 08:08 simkoG

Reproduce the problem

I couldn't reproduce the issue following that process.

Identify the root cause

However I guess the problem can be solved by adding a guard before use the preload table as asked in #5351. What do you think @piotrbak ?

CrochetFeve0251 avatar Aug 29 '22 11:08 CrochetFeve0251

It wouldn't make sense to guard the use of the table if it exists, as we want the cronjobs to run in CLI too for it

Tabrisrp avatar Aug 29 '22 14:08 Tabrisrp

@DahmaniAdame The problem with cache table that's not related to CLI is going to be fixed here: https://github.com/wp-media/wp-rocket/issues/5351

piotrbak avatar Sep 09 '22 12:09 piotrbak

@DahmaniAdame @piotrbak my idea when guarding the table is the fact that when we launch the preload queue from the cli it won't create the table if it is missing. But then if we open the admin it will create it making us think the table was there.

I tried some scenarios and that for the moment the only one I can reproduce that issue.

CrochetFeve0251 avatar Sep 09 '22 12:09 CrochetFeve0251

I can't replicate the issue either

Tabrisrp avatar Sep 23 '22 15:09 Tabrisrp

@CrochetFeve0251 @Tabrisrp If the issue is the one described by Cyrille here: https://github.com/wp-media/wp-rocket/issues/5361#issuecomment-1241928628

We could handle this on the CLI end maybe?

piotrbak avatar Sep 25 '22 17:09 piotrbak

@Tabrisrp What do you think about handling it inside the WP Rocket CLI itself? 🤔

piotrbak avatar Sep 29 '22 11:09 piotrbak

Moving it back to grooming as proposed solution prevents error from being triggered but doesn't resolve the initial problem. Maybe we could handle this on the CLI side? 🤔

piotrbak avatar Nov 18 '22 12:11 piotrbak

@simkoG This issue is most likely fixed as we look for the init hook while creating the tables, not admin_init. Your feedback will be very appreciated

piotrbak avatar Dec 14 '22 12:12 piotrbak

@piotrbak I can't replicate the issue for now. It seems it is fixed. If not I'll write back to you.

simkoG avatar Dec 15 '22 12:12 simkoG