Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removal of old log entries fails on large databases #143

Closed
foliovision opened this issue Jun 7, 2018 · 2 comments
Closed

Removal of old log entries fails on large databases #143

foliovision opened this issue Jun 7, 2018 · 2 comments

Comments

@foliovision
Copy link

Hello bonny,

we like your plugin a lot!

However on one of our client websites the database tables have more than 9 million entries (2 million rows in wp_simple_history and 7 million in wp_simple_history_contexts) and it's taking 2 GB of space in SQL. And we only started to use your plugin 6 months ago.

I can see there is a note like "Items in the database are automatically removed after 60 days." in Settings -> Simple History, but it doesn't seem to work.

So I checked that and found that 256M of PHP memory is not enough and it fails on these lines in inc/SimpleHistory.php:

// Get id of rows to delete
$sql = $wpdb->prepare(
    "SELECT id FROM $table_name WHERE DATE_ADD(date, INTERVAL %d DAY) < now()",
        $days
    );

$ids_to_delete = $wpdb->get_col( $sql );

So I set a limit for that query to 100,000 rows and let it run in loop until all the old logs are purged. For really big tables it might time out eventually, but then the next cron run will take care of that.

Could you please check our pull request here? #142

Thanks,
Martin

@bonny
Copy link
Owner

bonny commented Jun 16, 2018

Thanks Martin! I will add this to the next update.

Usually when the log grows big it's because of a lot of failed login attempts because of brute force attacks. Do you know if this was the case for you - or was it something else that was logged a really lot of times?

@bonny bonny closed this as completed Jun 16, 2018
@foliovision
Copy link
Author

Hello bonny,

yes, there was some action which was logged I think 1 million times in a single week.

Thank you for your cooperation!

Martin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants