? ? Pending

User tests: Successful: Unsuccessful:

avatar csthomas
csthomas
30 May 2018

Summary of Changes

Every observer that have an alias is attached and triggered twice. It started from #17739.
Ping @laoneo

Example: tags, content history.

I did test on saving existed article.
After patch there is ~20 queries less.

Tags and ucm_content are updated twice.

To test you can use below dirty patch to display queries from the POST request

diff --git a/libraries/joomla/database/driver.php b/libraries/joomla/database/driver.php
index f771013380..af6cb8bc74 100644
--- a/libraries/joomla/database/driver.php
+++ b/libraries/joomla/database/driver.php
@@ -78,19 +78,19 @@ abstract class JDatabaseDriver extends JDatabase implements JDatabaseInterface
 	 * @var    array  The log of executed SQL statements by the database driver.
 	 * @since  11.1
 	 */
-	protected $log = array();
+	public $log = array();
 
 	/**
 	 * @var    array  The log of executed SQL statements timings (start and stop microtimes) by the database driver.
 	 * @since  CMS 3.1.2
 	 */
-	protected $timings = array();
+	public $timings = array();
 
 	/**
 	 * @var    array  The log of executed SQL statements timings (start and stop microtimes) by the database driver.
 	 * @since  CMS 3.1.2
 	 */
-	protected $callStacks = array();
+	public $callStacks = array();
 
 	/**
 	 * @var    string  The character(s) used to quote SQL statement names such as table names or field names,
diff --git a/libraries/src/Application/WebApplication.php b/libraries/src/Application/WebApplication.php
index afac65dac0..4226c4f627 100644
--- a/libraries/src/Application/WebApplication.php
+++ b/libraries/src/Application/WebApplication.php
@@ -621,9 +621,15 @@ class WebApplication extends BaseApplication
 			}
 		}
 
+		// Trigger the onBeforeRespond event.
+		$this->triggerEvent('onBeforeRespond');
+
 		// Set appropriate headers
 		$this->respond();
 
+		// Trigger the onAfterRespond event.
+		$this->triggerEvent('onAfterRespond');
+
 		//  Close the application after the redirect.
 		$this->close();
 	}
diff --git a/plugins/system/debug/debug.php b/plugins/system/debug/debug.php
index e1989e945a..24b1c420fc 100644
--- a/plugins/system/debug/debug.php
+++ b/plugins/system/debug/debug.php
@@ -177,6 +177,27 @@ class PlgSystemDebug extends JPlugin
 
 		// Prepare disconnect handler for SQL profiling.
 		$db = $this->db;
+
+		$session = JFactory::getSession();
+
+		if ($session->get('dbLogs'))
+		{
+			$db->log = array_merge($session->get('dbLogs'), $db->log);
+			$session->set('dbLogs', null);
+		}
+
+		if ($session->get('dbTimings'))
+		{
+			$db->timings = array_merge($session->get('dbTimings'), $db->timings);
+			$session->set('dbTimings', null);
+		}
+
+		if ($session->get('dbCallStacks'))
+		{
+			$db->callStacks = array_merge($session->get('dbCallStacks'), $db->callStacks);
+			$session->set('dbCallStacks', null);
+		}
+
 		$db->addDisconnectHandler(array($this, 'mysqlDisconnectHandler'));
 
 		// Log deprecated class aliases
@@ -195,6 +216,14 @@ class PlgSystemDebug extends JPlugin
 		}
 	}
 
+	public function onBeforeRespond() {
+		$session = JFactory::getSession();
+
+		$session->set('dbLogs', $this->db->log);
+		$session->set('dbTimings', $this->db->timings);
+		$session->set('dbCallStacks', $this->db->callStacks);
+	}
+
 	/**
 	 * Add the CSS for debug.
 	 * We can't do this in the constructor because stuff breaks.
@@ -1214,7 +1243,7 @@ class PlgSystemDebug extends JPlugin
 
 		if ($this->totalQueries === 0)
 		{
-			$this->totalQueries = $db->getCount();
+			$this->totalQueries = count($db->getLog());
 		}
 
 		$html = array();
@@ -1485,7 +1514,7 @@ class PlgSystemDebug extends JPlugin
 	{
 		$db->setDebug(false);
 
-		$this->totalQueries = $db->getCount();
+		$this->totalQueries = count($db->getLog());
 
 		$dbVersion5037 = $db->getServerType() === 'mysql' && version_compare($db->getVersion(), '5.0.37', '>=');
 
avatar csthomas csthomas - open - 30 May 2018
avatar csthomas csthomas - change - 30 May 2018
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 30 May 2018
Category Libraries
avatar csthomas csthomas - change - 31 May 2018
Labels Added: ?
avatar csthomas csthomas - change - 8 Jun 2018
Title
Remove duplicate observers
Remove duplicate observers ~ 20 queries less while saving the article
avatar csthomas csthomas - edited - 8 Jun 2018
avatar carlitorweb
carlitorweb - comment - 8 Jun 2018

------BEFORE------

before

------AFTER------

after

avatar carlitorweb carlitorweb - test_item - 8 Jun 2018 - Tested successfully
avatar carlitorweb
carlitorweb - comment - 8 Jun 2018

I have tested this item successfully on 0cefbf6


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/20629.

avatar alikon alikon - test_item - 27 Aug 2018 - Tested successfully
avatar alikon
alikon - comment - 27 Aug 2018

I have tested this item successfully on 0cefbf6


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/20629.

avatar alikon
alikon - comment - 27 Aug 2018

I have tested this item successfully on 0cefbf6


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/20629.

avatar Quy Quy - change - 27 Aug 2018
Status Pending Ready to Commit
avatar Quy
Quy - comment - 27 Aug 2018

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/20629.

avatar Quy
Quy - comment - 27 Aug 2018

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/20629.

avatar mbabker mbabker - change - 3 Sep 2018
Status Ready to Commit Fixed in Code Base
Closed_Date 0000-00-00 00:00:00 2018-09-03 17:16:41
Closed_By mbabker
Labels Added: ?
avatar mbabker mbabker - close - 3 Sep 2018
avatar mbabker mbabker - merge - 3 Sep 2018

Add a Comment

Login with GitHub to post a comment