From 2e2fd9728707607c9ce8e835800f3666e0c88eff Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sun, 11 Feb 2018 17:08:58 +0000 Subject: [PATCH] Networks and Sites: In `get_site_by_path()`, use single `domain` and `path` parameters if there's only one item to look for. This should increase the chances of `WP_Site_Query::get_sites()` hitting an existing cache. Props spacedmonkey. Fixes #42299. git-svn-id: https://develop.svn.wordpress.org/trunk@42698 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/ms-load.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/ms-load.php b/src/wp-includes/ms-load.php index f2f53203ea..932ae76ca5 100644 --- a/src/wp-includes/ms-load.php +++ b/src/wp-includes/ms-load.php @@ -234,17 +234,21 @@ function get_site_by_path( $domain, $path, $segments = null ) { } $args = array( - 'domain__in' => $domains, - 'path__in' => $paths, - 'number' => 1, + 'number' => 1, ); if ( count( $domains ) > 1 ) { + $args['domain__in'] = $domains; $args['orderby']['domain_length'] = 'DESC'; + } else { + $args['domain'] = array_shift( $domains ); } if ( count( $paths ) > 1 ) { + $args['path__in'] = $paths; $args['orderby']['path_length'] = 'DESC'; + } else { + $args['path'] = array_shift( $paths ); } $result = get_sites( $args );