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

Replace slugs qts_page_request cache with transient #1182

Merged
merged 1 commit into from
Jun 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions modules/slugs/src/slugs-class-slugs.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,10 @@ public function query_vars( $query_vars ) {
if ( preg_match( "#^$match#", $request_match, $matches ) || preg_match( "#^$match#", urldecode( $request_match ), $matches ) ) {
if ( $wp_rewrite->use_verbose_page_rules && preg_match( '/pagename=\$matches\[(\d+)\]/', $query, $varmatch ) ) {
// this is a verbose page match, lets check to be sure about it
if ( ! $page_foundid = $this->get_page_by_path( $matches[ $varmatch[1] ] ) ) {
if ( ! $page_found = $this->get_page_by_path( $matches[ $varmatch[1] ] ) ) {
continue;
} else {
wp_cache_set( 'qts_page_request', $page_foundid ); // caching query :)
set_transient( 'qtranslate_slugs_matched_page', $page_found, 30 ); // Store the matched page for `filter_request`.
}
}
// Got a match.
Expand Down Expand Up @@ -374,17 +374,17 @@ function filter_request( $query ) {

// -> page
elseif ( isset( $query['pagename'] ) || isset( $query['page_id'] ) ):
$page = wp_cache_get( 'qts_page_request' );
if ( ! $page ) {
$page = get_transient( 'qtranslate_slugs_matched_page' );
if ( $page === false ) {
$page = isset( $query['page_id'] ) ? get_post( $query['page_id'] ) : $this->get_page_by_path( $query['pagename'] );
}
delete_transient( 'qtranslate_slugs_matched_page' );
if ( ! $page ) {
return $query;
}
$id = $page->ID;
$cache_array = array( $page );
update_post_caches( $cache_array, 'page' ); // caching query :)
wp_cache_delete( 'qts_page_request' );
update_post_caches( $cache_array, 'page' );
Copy link
Collaborator Author

@herrvigg herrvigg Jun 6, 2022

Choose a reason for hiding this comment

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

Not related to this patch, but I'm not sure about this update_post_caches and all similar updates in QTS.

Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if it's really needed, also because we are not modifying the post objects here. But I don't think it has anything to do with the caching query :) comment btw.
This is calling eventually wp_cache_add_multiple, so I think is not updating anything most of the time (it will only update if those keys do not exist already).
We may just add a comment to double check later or remove the calls now...

$query['pagename'] = get_page_uri( $page );
$function = 'get_page_link';

Expand Down