From: Alexander Ebert Date: Sat, 22 Aug 2020 21:05:23 +0000 (+0200) Subject: Improved the performance of reading tags without a specific language id X-Git-Tag: 5.3.0_Alpha_1~29 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=95939e32de17b466f6588dd150c9bc0fd29fa42a;p=GitHub%2FWoltLab%2FWCF.git Improved the performance of reading tags without a specific language id --- diff --git a/wcfsetup/install/files/lib/system/tagging/TagEngine.class.php b/wcfsetup/install/files/lib/system/tagging/TagEngine.class.php index db14f92976..3578026f68 100644 --- a/wcfsetup/install/files/lib/system/tagging/TagEngine.class.php +++ b/wcfsetup/install/files/lib/system/tagging/TagEngine.class.php @@ -6,6 +6,7 @@ use wcf\data\tag\TagAction; use wcf\data\tag\TagList; use wcf\system\database\util\PreparedStatementConditionBuilder; use wcf\system\exception\InvalidObjectTypeException; +use wcf\system\language\LanguageFactory; use wcf\system\SingletonFactory; use wcf\system\WCF; use wcf\util\ArrayUtil; @@ -163,9 +164,17 @@ class TagEngine extends SingletonFactory { if (!$languageID) unset($languageIDs[$index]); } - if (!empty($languageIDs)) { - $conditions->add("tag_to_object.languageID IN (?)", [$languageIDs]); + // The `languageID` is part of the index, skipping it will cause MySQL to skip the + // `objectID` column, causing a partial table scan. + if (empty($languageIDs)) { + // The `languageID` column is never null, tags are always assigned to a language + // thus we cannot use the content language ids here. + foreach (LanguageFactory::getInstance()->getLanguages() as $language) { + $languageIDs[] = $language->languageID; + } } + + $conditions->add("tag_to_object.languageID IN (?)", [$languageIDs]); } $sql = "SELECT tag.*, tag_to_object.objectID