Making WordPress.org

Changeset 7806


Ignore:
Timestamp:
10/31/2018 03:02:42 AM (6 years ago)
Author:
dd32
Message:

Support Forums: Disable canonical on 404 requests when a short name query var is provided.

This is to avoid some expensive database queries which causes out-of-memory fatal errors on the Support Forum.

Fixes #3894.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-performance-optimizations.php

    r6564 r7806  
    3939        // Disable post meta key lookup, see https://core.trac.wordpress.org/ticket/33885.
    4040        add_filter( 'postmeta_form_keys', '__return_empty_array' );
     41
     42        // Disable canonical redirects for short post_names
     43        add_filter( 'template_redirect', array( $this, 'maybe_disable_404_canonical' ), 9 );
     44
     45    }
     46
     47    /**
     48     * Disables Canonical redirects on 404 pages when a short (<5char) name is provided.
     49     *
     50     * This is used to avoid really bad queries in redirect_guess_404_permalink() on urls such as:
     51     * https://wordpress.org/support/topic/test/*1*
     52     */
     53    public function maybe_disable_404_canonical() {
     54        if ( is_404() && get_query_var( 'name' ) && strlen( get_query_var( 'name' ) ) < 5 ) {
     55            remove_filter( 'template_redirect', 'redirect_canonical' );
     56        }
    4157    }
    4258
Note: See TracChangeset for help on using the changeset viewer.