Cache request information for SQL queries
authorTim Düsterhus <duesterhus@woltlab.com>
Sun, 2 Feb 2020 14:59:10 +0000 (15:59 +0100)
committerTim Düsterhus <duesterhus@woltlab.com>
Sun, 2 Feb 2020 15:05:07 +0000 (16:05 +0100)
wcfsetup/install/files/lib/system/database/Database.class.php

index 8fd5af789d7341eaffda241f28bea4299b460e25..b2d16505544b3a5d4d31ed4ecc5c60bea09bf6fa 100644 (file)
@@ -259,13 +259,16 @@ abstract class Database {
                        // Note: This is meant to be run unconditionally in production to be
                        //       useful. Thus the code to retrieve the request information
                        //       must be absolutely lightweight.
-                       $requestInformation = '';
-                       if (defined('ENABLE_PRODUCTION_DEBUG_MODE') && ENABLE_PRODUCTION_DEBUG_MODE && isset($_SERVER['REQUEST_URI'])) {
-                               $requestInformation = substr($_SERVER['REQUEST_URI'].(\wcf\getRequestId() ? ' ('.\wcf\getRequestId().')' : ''), 0, 90);
-                               if (isset($_REQUEST['className']) && isset($_REQUEST['actionName'])) {
-                                       $requestInformation .= ' ('.$_REQUEST['className'].':'.$_REQUEST['actionName'].')';
+                       static $requestInformation = null;
+                       if ($requestInformation === null) {
+                               $requestInformation = '';
+                               if (defined('ENABLE_PRODUCTION_DEBUG_MODE') && ENABLE_PRODUCTION_DEBUG_MODE && isset($_SERVER['REQUEST_URI'])) {
+                                       $requestInformation = substr($_SERVER['REQUEST_URI'].(\wcf\getRequestId() ? ' ('.\wcf\getRequestId().')' : ''), 0, 90);
+                                       if (isset($_REQUEST['className']) && isset($_REQUEST['actionName'])) {
+                                               $requestInformation .= ' ('.$_REQUEST['className'].':'.$_REQUEST['actionName'].')';
+                                       }
+                                       $requestInformation = substr($requestInformation, 0, 180);
                                }
-                               $requestInformation = substr($requestInformation, 0, 180);
                        }
                        
                        $pdoStatement = $this->pdo->prepare($statement.($requestInformation ? " -- ".$this->pdo->quote($requestInformation) : ''));