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

Use a transient to cache the potentially slow "Pending URLs Count" query #3222

Merged
merged 7 commits into from
Sep 10, 2019

Conversation

schlessera
Copy link
Collaborator

Extracts the pending URL count query into a separate method and then wraps usage of that method into a transient.

The key name is amp_pending_urls_count and the expiry time is set to 24h.

Fixes #2736

@schlessera schlessera added Validation P2 Low priority labels Sep 10, 2019
@googlebot googlebot added the cla: yes Signed the Google CLA label Sep 10, 2019
@@ -82,6 +82,13 @@ class AMP_Validated_URL_Post_Type {
*/
const VALIDATION_ERRORS_META_BOX = 'amp_validation_errors';

/**
* The transient key to use for caching the pending URLs count.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of "pending" it would be more accurate to use "new" for the changes here. The URLs being queried are those with new accepted/rejected validation errors:

					AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_REJECTED_STATUS,
					AMP_Validation_Error_Taxonomy::VALIDATION_ERROR_NEW_ACCEPTED_STATUS,

As opposed to ack rejected/accepted errors.

Using new instead of pending would be more consistent in regards to terminology.

But given the resulting containing element is pending-count, I don't feel strongly about this.

Copy link
Collaborator Author

@schlessera schlessera Sep 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't feel strongly about this either, but I think the containing element should properly reflect this as well, then. Do you want me to rename both? I don't assume people provide custom styling for this, so BC is probably not an issue here...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pending-count class name is only appearing here because the Comments admin menu item also uses it, and the markup for it was copied:

image

I thought that pending-count had some styles associated with it, but this is not the case. Feel free to rename the class name as you see fit as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in b887ee5

@westonruter westonruter added this to the v1.3 milestone Sep 10, 2019
@westonruter westonruter self-requested a review September 10, 2019 16:38
@westonruter westonruter merged commit 919bdb8 into develop Sep 10, 2019
@westonruter westonruter deleted the add/2736-cache-menu-invalid-url-count branch September 10, 2019 20:45
set_transient( static::NEW_VALIDATION_ERROR_URLS_COUNT_TRANSIENT, $new_validation_error_urls, DAY_IN_SECONDS );
}

if ( 0 === $new_validation_error_urls ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: The strict equality here caused a regression since integers stored in transients when no persistent object cache is used will get cast to strings. See #3478.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Signed the Google CLA P2 Low priority Validation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cache query result in add_admin_menu_new_invalid_url_count
3 participants