Open Source PHP RAD Framework with UI.

PHPDS_query asWhole can be performance tuned

Reported by Don Schoeman on 2012-07-12
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
PHPDevShell
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.

Related branches

Greg (gregfr) wrote :

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

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) on 2012-07-12
Changed in phpdevshell:
status: New → Fix Committed
Greg (gregfr) wrote :

Looks good :)

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

Other bug subscribers