We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28042 ☆ A M B ☆
    • 24,524 Posts
    I had thought that the DPAPI was put into its own class for snippets, modules, etc to use if they didn’t need the whole parser class. The problem is that it uses the parser class in 19 places (in connect(), in query() and in getRow(); the first two is for timing, the third is to send an error message), which means that it can’t be used without first instantiating the parser class! Which totally defeats the purpose of breaking it out into its own class (well, except for making it possible to support other databases besides mysql).

    For my own use, I’m going to add a line of code to check for the existance of the $modx object before the calls, since none of them are vital.
      Studying MODX in the desert - http://sottwell.com
      Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
      Join the Slack Community - http://modx.org
      • 25663 MODX Staff
      • 12,272 Posts
      Susan, do you think this could be a source of a lot of the slowdowns as compared to Eto?
        Ryan Thrash, MODX Co-Founder
        Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        If all these timing loops aren’t in Eto, most certainly. Every query to the database is getting the timing loop, since all the functions use the query() function internally.

        This is what I changed in dbapi.mysql.class.inc.php:

        added a rudimentary error function at the end of the class:
        	
        function errorMsg($msg="Database Error") {
            echo $msg;
        }


        Made the timing section into a conditional block and used the new errorMsg function in connect:
        function connect($host='',$dbase='', $uid='',$pwd='',$persist=0){
            $uid = $uid ? $uid:$this->config['user'];
            $pwd = $pwd ? $pwd:$this->config['pass'];
            $host = $host ? $host:$this->config['host'];
            $dbase = $dbase ? $dbase:$this->config['dbase'];
            if(@!$this->conn = ($persist ? mysql_pconnect($host, $uid, $pwd):mysql_connect($host, $uid, $pwd))) {
                $this->errorMsg("Failed to create the database connection!");
        	exit;
            } else {
                $dbase = str_replace('`','',$dbase); // remove the `` chars
                if(!@mysql_select_db($dbase)) {
                    $this->errorMsg("Failed to select the database."); // error message
                    exit;
                }
                 // check for modx object
                if(is_object($modx)) {
                    $tend = $modx->getMicroTime(); 
                    $totaltime = $tend-$tstart;
                     if($modx->dumpSQL) {
                        $modx->queryCode .= "<fieldset style='text-align:left'><legend>Database connection</legend>".sprintf("Database connection was created in %2.4f s", $totaltime)."</fieldset><br />";
                    }
                    $this->queryTime = $this->queryTime+$totaltime;
                }
                $this->isConnected = true;
            }	
        }


        In query, likewise:
        function query($sql) {
            if(empty($this->conn)||!is_resource($this->conn)) {
                $this->connect();
            }
            if(is_object($modx)) { // check for modx object
                $tstart = $modx->getMicroTime(); 
            }
            if(!$result = @mysql_query($sql, $this->conn)) {
        	this->errorMsg("Execution of a query to the database failed."); //error message
            } else {
                if(is_object($modx)) { // check for modx object
                    $tend = $modx->getMicroTime(); 
                    $totaltime = $tend-$tstart;
                    $modx->queryTime = $modx->queryTime+$totaltime;
                    if($modx->dumpSQL) {
                        $modx->queryCode .= "<fieldset style='text-align:left'><legend>Query ".($this->executedQueries+1)." - ".sprintf("%2.4f s", $totaltime)."</legend>".$sql."</fieldset><br />";
                    }
                    $modx->executedQueries = $modx->executedQueries+1;
                }
        	return $result;
            }
        }


        And in getRow I changed the error message into a default:
        function getRow($ds,$mode='assoc'){
            if($ds) {
                if($mode=='assoc') {
                    return mysql_fetch_assoc($ds);
                }
        	elseif($mode=='num') {
        		return mysql_fetch_row($ds);
        	}
        	elseif($mode=='both') {
        		return mysql_fetch_array($ds, MYSQL_BOTH);		
        	}
        	else {
        		return mysql_fetch_row($ds); // default to numeric
        	}
            }
        }
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org
          • 25663 MODX Staff
          • 12,272 Posts
          Can you run a quick b/a test on a couple of pages with the code revisions, so we can see the performance delta? If it’s as good as I suspect, and if there are no unforseen issues with the changes, I’d like to make this a part of 3.3.
            Ryan Thrash, MODX Co-Founder
            Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            My code revisions aren’t really suitable for that; the timing will still run if it’s in the parser. I just did this because I’m working on a Sriptaculous sorting method for the chunk containing the options for the Sideblock selection TV, and the .php file doesn’t need to have the whole parser included. So far I’ve got the chunk contents loaded using basic prototype functions; now I need to turn the div it’s displayed in into a sortable container, pass the revised list back and replace the chunk contents into the database.

            I’ll take a break to clear my head from javascript, then come back and see about running a normal page with and without the timing loops in the database. Should be done in a couple of hours; going for an evening walk first.
              Studying MODX in the desert - http://sottwell.com
              Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
              Join the Slack Community - http://modx.org
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              I fiddled with it, removed it, all sorts of things, and didn’t see any difference at all. I think I’m missing something somewhere, because that should make at least a little difference.
                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org