Open kasparsd opened 4 years ago
I can confirm, this is happening on one of our client site as well. Oldest records available are now from 2016. This site was not intended to have an eternal memory.
I am starting review of this today and will carve out some time to investigate/fix this week.
@kasparsd did you do any research into how the cron schedules run for deleting the logs. WordPress Cron is notorious for missing events without a dedicated native cron to trigger WordPress Cron. I have a suspicion this may be related to these records not being removed and posted a question in the WordPress support forum topic related to this issue.
@kopepasah The method used for deleting the older logs is defined here:
Notice that it has several conditionals which can stop the deletion from happening. I haven't verified if all of them work as expected.
The wp_stream_auto_purge
action is scheduled here to run twice per day:
There is also a test case for this method and it appears to be passing:
@kasparsd @kopepasah I have done some testing and I can see that the plugin options are empty on my environments.
https://github.com/xwp/stream/blob/d465e3534d6f3f8fed4ee656a15412592355bfbd/classes/class-admin.php#L752
This is an empty array as the wp_stream
option is not saved to the database.
After changing the values in the plugin settings and saving multiple times, it does update them and I can then run wp cron event run wp_stream_auto_purge
with succession.
Whilst the event could run to completion on some environments and entries are removed, it does not work for a site that has 5,883,474 entries (294,174 pages) as it times out.
user@hostname:~/public/current$ wp cron event run wp_stream_auto_purge
WordPress database error Lock wait timeout exceeded; try restarting transaction for query DELETE `stream`, `meta`
FROM wp_stream AS `stream`
LEFT JOIN wp_stream_meta AS `meta`
ON `meta`.`record_id` = `stream`.`ID`
WHERE 1=1 AND `stream`.`created` < '2020-07-06 17:01:33'; made by include('phar:///usr/local/bin/wp/php/boot-phar.php'), include('phar:///usr/local/bin/wp/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('wp_stream_auto_purge'), WP_Hook->do_action, WP_Hook->apply_filters, WP_Stream\Admin->purge_scheduled_action
Executed the cron event 'wp_stream_auto_purge' in 51.741s.
Reopening since #1159 has been reverted.
From https://wordpress.org/support/topic/old-records-are-not-being-removed/
Duplicate reports: