Skip to content

Garbage-collect validated URL posts which have all validation errors reviewed, and remove empty validation error terms #4779

@westonruter

Description

@westonruter

Feature description

When a URL is validated, an amp_validated_url post type instance is created to capture the results of validating the page for AMP validation issues. Other data is stored in postmeta as well, including the queried object, the stylesheets, and details for any validation error that occured. At present, these validated URLs remain in perpetuity until a user manually selects validated URLs to “forget” (that is, delete). And with #1756 the validated URLs will be created in the background on an ongoing basis. This isn't great because as was reported on the support forum, these posts and their postmeta actually consume a lot of storage. What's more is that the validated URLs actually serve no real purpose once all of the validation errors on them have been reviewed (or if they have no validation errors in the first place).

Therefore, we should introduce a WP Cron task which goes through on a daily basis to forget (delete) all amp_validated_url posts which are older than 1 week and which also have no unreviewed validation errors. Whenever a URL is validated (or re-validated) its post_date is set to the current datetime, so this process will only delete URLs that haven't been touched in a week.

This means of garbage collection is similar to how auto-draft posts are deleted after a week. See wp_delete_auto_drafts(). The difference for our purposes here is that we will skip any posts that have unreviewed validation errors. Note that this can be done by simply joining the wp_posts table with the amp_validation_error taxonomy terms which have the term_group set to 0 (unreviewed kept) or 1 (unreviewed removed).

Additionally, during the same process we also need to delete amp_validation_error terms in the reviewed state (reviewed removed and reviewed kept) that have zero URLs associated with them.


Do not alter or remove anything below. The following sections will be managed by moderators only.

Acceptance criteria

Implementation brief

QA testing instructions

Demo

Changelog entry

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions