Simplify RoutingCacheBuilder::getCustomUrls()
authorTim Düsterhus <duesterhus@woltlab.com>
Thu, 2 Jun 2022 10:08:36 +0000 (12:08 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Thu, 2 Jun 2022 10:08:36 +0000 (12:08 +0200)
By creating the arrays for all known abbreviations early we can avoid checking
the existence of them over and over again.

wcfsetup/install/files/lib/system/cache/builder/RoutingCacheBuilder.class.php

index 0c6548ef3b4dd0ebedc9c1e95f57dd49b2108a3f..905bbe935d4d63fc5c2ca70d1fac993fcd002b1e 100644 (file)
@@ -239,6 +239,11 @@ class RoutingCacheBuilder extends AbstractCacheBuilder
             return $data;
         }
 
+        foreach (ApplicationHandler::getInstance()->getAbbreviations() as $abbreviation) {
+            $data['lookup'][$abbreviation] = [];
+            $data['reverse'][$abbreviation] = [];
+        }
+
         // fetch pages with a controller and a custom url
         $sql = "SELECT  controller,
                         controllerCustomURL,
@@ -270,11 +275,6 @@ class RoutingCacheBuilder extends AbstractCacheBuilder
             $packageID = $row['applicationPackageID'];
             $abbreviation = ApplicationHandler::getInstance()->getAbbreviation($packageID);
 
-            if (!isset($data['lookup'][$abbreviation])) {
-                $data['lookup'][$abbreviation] = [];
-                $data['reverse'][$abbreviation] = [];
-            }
-
             if (isset($row['controller'])) {
                 $data['lookup'][$abbreviation][$customUrl] = $row['controller'];
                 $data['reverse'][$abbreviation][$this->classNameToControllerName($row['controller'])] = $customUrl;
@@ -289,10 +289,6 @@ class RoutingCacheBuilder extends AbstractCacheBuilder
         foreach ($this->brokenControllers as $type => $brokenControllers) {
             foreach ($brokenControllers as $application => $controllers) {
                 foreach ($controllers as $key => $value) {
-                    if (!isset($data[$type][$application])) {
-                        $data[$type][$application] = [];
-                    }
-
                     if (!isset($data[$type][$application][$key])) {
                         $data[$type][$application][$key] = $value;
                     }