PHPDS_query asWhole can be performance tuned

Bug #1023801 reported by Don Schoeman
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
PHPDevShell
Fix Committed
High
Don Schoeman

Bug Description

PHPDS_query's asWhole() function is called when multiple rows are requested from the database and it returns a big array of arrays as the result. The function is called multiple times on nearly every page. The asWhole() function can also do extra manipulation on the data based on the keyField and focus optional parameters. However, both the KeyField and focus options are used in very rare occasions within PHPDevshell itself, yet, a number of unnecessary assignments and conditional checks are performed on each row of the result set regardless of the KeyField and focus options.

This function can be optimised by first checking whether the keyField or focus parameter is set. If none of the two parameters is set it can then loop through the result set much more efficiently.

Tags: aswhole

Related branches

Revision history for this message
Greg (gregfr) wrote :

I agree but you have to be very careful on how to decide to skip the loop.

Revision history for this message
Don Schoeman (don.sch) wrote :

My replacement function will look something like this:

 public function asWhole()
 {
  $result = array();
  $count = 0;

  if ($this->keyField || !empty($this->focus)) {
   while ($row = $this->asLine()) {
    $count++;
    $key = $this->getKey($row);

    if (!empty($this->focus)) {
     $row = (isset($row[$this->focus])) ? $row[$this->focus] : null;
    }
    if ($row || !empty($this->noEmptyRow)) {
     if ($key) {
      $result[$key] = $row;
     } else {
      $result[] = $row;
     }
    }
   }
  } else {
   while ($row = $this->asLine()) {
    $count++;
    $result[] = $row;
   }
  }

  $this->rowCount = $count;
  return $result;
 }

Don Schoeman (don.sch)
Changed in phpdevshell:
status: New → Fix Committed
Revision history for this message
Greg (gregfr) wrote :

Looks good :)

Greg (gregfr)
Changed in phpdevshell:
milestone: 3.2.1-stable → 3.5
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.