stream icon indicating copy to clipboard operation
stream copied to clipboard

Old records are not being removed

Open kasparsd opened this issue 5 years ago • 6 comments

From https://wordpress.org/support/topic/old-records-are-not-being-removed/

I have a few sites with the Stream plugin installed. I just noticed that none of them are removing old records. I have the “Keep Records for” setting set to 30, but with records going back more than a year. They aren’t being removed. Any idea why that would happen and how to resolve it?

Duplicate reports:

  • https://wordpress.org/support/topic/records-not-automatically-deleting/

kasparsd avatar Mar 19 '20 18:03 kasparsd

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.

lkraav avatar Apr 22 '20 10:04 lkraav

I am starting review of this today and will carve out some time to investigate/fix this week.

kopepasah avatar Jun 30 '20 22:06 kopepasah

@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 avatar Jul 07 '20 19:07 kopepasah

@kopepasah The method used for deleting the older logs is defined here:

https://github.com/xwp/stream/blob/d465e3534d6f3f8fed4ee656a15412592355bfbd/classes/class-admin.php#L735-L779

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:

https://github.com/xwp/stream/blob/d465e3534d6f3f8fed4ee656a15412592355bfbd/classes/class-admin.php#L724-L728

There is also a test case for this method and it appears to be passing:

https://github.com/xwp/stream/blob/4c60b9c84a7d136a663e09266ba0de9a7b1f04ab/tests/tests/test-class-admin.php#L270-L307

kasparsd avatar Jul 08 '20 07:07 kasparsd

@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.

codepuncher avatar Aug 06 '20 08:08 codepuncher

Reopening since #1159 has been reverted.

kasparsd avatar Feb 12 '21 06:02 kasparsd