#3395 closed enhancement (fixed)
Akismet spam cleanup functionality
Reported by: | stephdau | Owned by: | johnjamesjacoby |
---|---|---|---|
Milestone: | 2.6.7 | Priority: | high |
Severity: | normal | Version: | |
Component: | Extend - Akismet | Keywords: | has-patch commit |
Cc: |
Description
This was first proposed on Slack here.
In the WP AK plugin, we have a scheduled function Akismet::delete_old_comments_meta() to delete old akismet_as_submitted meta records, because they are pretty large, and not useful at all after a while.
Since then, @johnjamesjacoby suggested:
We could go as far as moving it out of post meta and into a custom post type with a post_parent relationship to the topic/reply. That would allow for some longer data retention, without the surplus of metadata keys.
I'm attaching a patch with what I had started before JJJ add his comment, since I have it, but leaving any fancier concept to the bbPress team to bounce around.
Note that my patch does not actually have the scheduling of said cleanup, as I wasn't sure where it would be best to trigger that in bbPress. See:
/** * The above will need to be scheduled with something like: * if ( ! wp_next_scheduled( 'akismet_scheduled_delete' ) ) { * wp_schedule_event( time(), 'daily', 'akismet_scheduled_delete' ); * } */
Also note that the patch in wholly untasted, since I didn't get to keep going. :)
Attachments (5)
Change History (32)
#2
@
4 years ago
- Keywords has-patch needs-testing added
- Milestone changed from Awaiting Review to 2.7
- Owner set to johnjamesjacoby
- Priority changed from normal to high
- Status changed from new to assigned
Patch looks really good to me. Let's milestone this for 2.7, and I'll be sure to test this thoroughly then. 🙏
#4
@
3 years ago
Any chance this could make it in sooner rather than later?
It's been 13 months now. :)
#5
@
3 years ago
3395.2.diff includes the following changes:
- Removed/improved some related code docs
- Replace
return;
statements withbreak;
inside ofwhile
loops, so that table optimizations still run - Pass more variables into hooks, to make them potentially more useful later
- Add a
maybe_optimize_postmeta()
method to encapsulate some repeated code - Add docs on filters
- Relocate filter names, because I think they were inverted (count vs. batch)?
@stephdau what do you think, old friend? 🍕
#12
@
3 years ago
FYI; These cleanup methods appear to be very heavy on some sites, for example, on WordPress.org/bbPress.org/Buddypress.org the following errors are being triggered:
E_ERROR: Allowed memory size of 268435456 bytes exhausted (tried to allocate 16777224 bytes) in wp-includes/wp-db.php:1544 or E_ERROR: Maximum execution time of 100 seconds exceeded in wp-includes/wp-db.php:1447 Source: <Cron request, or wp-cli cron runner> Current filter: akismet_scheduled_delete - attached to priority 10: BBP_Akismet->delete_old_spam, BBP_Akismet->delete_old_spam_meta, BBP_Akismet->delete_orphaned_spam_meta, Akismet::delete_old_comments, Akismet::delete_old_comments_meta, Akismet::delete_orphaned_commentmeta
I'm not certain what Query / or which hooked filter is running during those errors, but this started happening around October 12th, which is about the time that a sync of other code from bbPress to w.org happened.
The maximumn time error appears to be in wpdb::prepare()
and the OOM appears to be within print_error()
, suggesting an extra-large SQL query being run too given how much memory it's trying to store.
Potentially related, is that Akismet always defines AKISMET_DELETE_LIMIT
as 100,000 where as the above change uses 10,000 otherwise. I've raised that with the Akismet team.
#13
@
3 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
Ahah, I found it. A little different than I thought.
[24-Nov-2021 07:00:42 UTC] База даних WordPress повернула помилку Unknown column 'post_id' in 'where clause' у відповідь на запит DELETE FROM wp_posts WHERE post_id IN ( '175', '221', '299', '461', '494', '498' ), виконаний do_action_ref_array('akismet_scheduled_delete'), WP_Hook->do_action, WP_Hook->apply_filters, BBP_Akismet->delete_old_spam, hyperdb->query, wpdb->print_error, hyperdb->get_caller
-
includes/extend/akismet.php
1037 1037 $format_string = implode( ", ", array_fill( 0, count( $spam_ids ), '%s' ) ); 1038 1038 1039 1039 // Run the delete queries 1040 $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->posts} WHERE post_idIN ( " . $format_string . " )", $spam_ids ) );1040 $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->posts} WHERE ID IN ( " . $format_string . " )", $spam_ids ) ); 1041 1041 $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->postmeta} WHERE post_id IN ( " . $format_string . " )", $spam_ids ) ); 1042 1042 1043 1043 // Clean the post cache for these topics & replies
This ticket was mentioned in Slack in #bbpress by dd32. View the logs.
3 years ago
#16
follow-up:
↓ 18
@
3 years ago
3395.3.diff includes the following changes:
- Incorporate feedback from @dd32
- Replace
p.id
withp.ID
in 2 more queries - Reduce interval from
10000
to1000
- Incorporate
AKISMET_DELETE_LIMIT
constant and_bbp_akismet_delete_spam_limit
filter into the other 2 clean-up methods, allowing them to be adjusted when necessary
Another idea is to use bbp_is_large_install()
(or some other database query) to guess at an appropriate limit. That seems out of scope to getting this fixed up, though.
#17
@
3 years ago
3395.4.diff iterates on 3395.3.diff in the following ways:
- Turns duplicate
LIMIT
code into a new method:get_delete_limit()
- Turns duplicate
DAY
code into a new method:get_delete_interval()
- Both methods accept filter parameters, so they can continue to be unique
- Removes superfluous
intval()
calls since they are cast as(int)
previously - Minor string formatting changes for consistency
#18
in reply to:
↑ 16
;
follow-ups:
↓ 20
↓ 22
@
3 years ago
Replying to johnjamesjacoby:
- Reduce interval from
10000
to1000
I'm not sure that's really useful here.. Since Akismet always defines it as 100,000: https://plugins.trac.wordpress.org/browser/akismet/trunk/akismet.php?marks=43#L40
Sites can't even override it without PHP warnings by defining it first :shrug:
#20
in reply to:
↑ 18
;
follow-up:
↓ 21
@
3 years ago
Replying to dd32:
Sites can't even override it without PHP warnings by defining it first :shrug:
True. We'll look into that, but they can override the limit by using the `akismet_delete_comment_limit` filter.
#22
in reply to:
↑ 18
@
3 years ago
Replying to dd32:
Sites can't even override it without PHP warnings by defining it first :shrug:
I'd like to propose that bbPress simply omit the usage of the constant.
The complexity and quantity of meta data in bbPress is almost-always guaranteed to be larger than Comments, so using that same value for both may actually be counter-intuitive to administrators.
Thoughts? 🧐
Another note: I will be off on a sabbatical in Sept/Oct/Nov, so I'll tag my fellow Akismet devs on this ticket, so they can keep up with it, and your team.
Ping @cfinke and @procifer. Tag! ;p