Query Optimization

MarcusF - October 20, 2009 - 11:41
Project:Signwriter
Version:6.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:patch (to be ported)
Description

Optimize SQL Querys with static cachin' because we have to much querys with same Select Statements.

signwriter.module Line: 568 signwriter_load_profile

function signwriter_load_profile($p) {

  static $profiles;
 
  $id = is_numeric($p) ? $p : (!empty($p->id) ? $p->id : 0);
  $name = is_string($p) ? $p : (!empty($p->name) ? $p->name : '');
 
  if ($id) {
 
    if (is_array($profiles) && array_key_exists($p, $profiles) )
    {
    $profile = $profiles[$p];
    }else
    {
    $profile = db_fetch_object(db_query("SELECT * FROM {signwriter} WHERE id = %d", $id));
    $profiles[$p] = $profile;
    }
    return $profile;
  }
  else {
    return db_fetch_object(db_query("SELECT * FROM {signwriter} WHERE name = '%s'", $name));
  }
}

 
 

Drupal is a registered trademark of Dries Buytaert.