Ignore:
Timestamp:
2011/03/18 21:42:22 (13 years ago)
Author:
shutta
Message:

refs #1173
カテゴリーカウント処理が重かったのを修正。
sfGetParents*、sfGetChildren* 絡みの処理効率を改善。

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/version-2_5-dev/data/class/helper/SC_Helper_DB.php

    r20718 r20726  
    744744            $arrTgtCategory_id[] = $parent_category_id; 
    745745            $arrParentID = $this->sfGetParents('dtb_category', 'parent_category_id', 'category_id', $parent_category_id); 
    746             foreach($arrParentID as $pid) { 
    747                 $arrTgtCategory_id[] = $pid; 
    748             } 
     746            $arrTgtCategory_id = array_merge($arrTgtCategory_id, $arrParentID); 
    749747        } 
    750748 
     
    815813     */ 
    816814    function sfGetChildrenArray($table, $pid_name, $id_name, $id) { 
    817         $objQuery =& SC_Query_Ex::getSingletonInstance(); 
    818         $col = $pid_name . "," . $id_name; 
    819         $arrData = $objQuery->select($col, $table); 
    820  
    821         $arrPID = array(); 
    822         $arrPID[] = $id; 
    823815        $arrChildren = array(); 
    824         $arrChildren[] = $id; 
    825  
    826         $arrRet = SC_Helper_DB_Ex::sfGetChildrenArraySub($arrData, $pid_name, $id_name, $arrPID); 
     816        $arrRet = array($id); 
    827817 
    828818        while(count($arrRet) > 0) { 
    829819            $arrChildren = array_merge($arrChildren, $arrRet); 
    830             $arrRet = SC_Helper_DB_Ex::sfGetChildrenArraySub($arrData, $pid_name, $id_name, $arrRet); 
     820            $arrRet = SC_Helper_DB_Ex::sfGetChildrenArraySub($table, $pid_name, $id_name, $arrRet); 
    831821        } 
    832822 
     
    843833     * @return array 子IDの配列 
    844834     */ 
    845     function sfGetChildrenArraySub($arrData, $pid_name, $id_name, $arrPID) { 
     835    function sfGetChildrenArraySub($table, $pid_name, $id_name, $arrPID) { 
     836        $objQuery =& SC_Query_Ex::getSingletonInstance(); 
     837 
     838        $where = "$pid_name IN (" . implode(',', array_fill(0, count($arrPID), '?')) . ")"; 
     839 
     840        $ret = $objQuery->select($id_name, $table, $where, $arrPID); 
     841 
    846842        $arrChildren = array(); 
    847         $max = count($arrData); 
    848  
    849         for($i = 0; $i < $max; $i++) { 
    850             foreach($arrPID as $val) { 
    851                 if($arrData[$i][$pid_name] == $val) { 
    852                     $arrChildren[] = $arrData[$i][$id_name]; 
    853                 } 
    854             } 
    855         } 
     843        foreach ($ret as $val) { 
     844            $arrChildren[] = $val[$id_name]; 
     845        } 
     846 
    856847        return $arrChildren; 
    857848    } 
     
    869860    function sfGetParents($table, $pid_name, $id_name, $id) { 
    870861        $arrRet = SC_Helper_DB_Ex::sfGetParentsArray($table, $pid_name, $id_name, $id); 
    871         // 配列の先頭1つを削除する。 
    872         array_shift($arrRet); 
    873862        return $arrRet; 
    874863    } 
     
    884873     */ 
    885874    function sfGetParentsArray($table, $pid_name, $id_name, $id) { 
    886         $objQuery =& SC_Query_Ex::getSingletonInstance(); 
    887         $col = $pid_name . "," . $id_name; 
    888         $arrData = $objQuery->select($col, $table); 
    889  
    890875        $arrParents = array(); 
    891         $arrParents[] = $id; 
    892         $child = $id; 
    893  
    894         $ret = SC_Helper_DB_Ex::sfGetParentsArraySub($arrData, $pid_name, $id_name, $child); 
    895  
    896         while($ret != "") { 
     876        $ret = $id; 
     877 
     878        while($ret != "0") { 
    897879            $arrParents[] = $ret; 
    898             $ret = SC_Helper_DB_Ex::sfGetParentsArraySub($arrData, $pid_name, $id_name, $ret); 
    899         } 
    900  
    901         $arrParents = array_reverse($arrParents); 
     880            $ret = SC_Helper_DB_Ex::sfGetParentsArraySub($table, $pid_name, $id_name, $ret); 
     881        } 
    902882 
    903883        return $arrParents; 
     
    905885 
    906886    /* 子ID所属する親IDを取得する */ 
    907     function sfGetParentsArraySub($arrData, $pid_name, $id_name, $child) { 
    908         $max = count($arrData); 
    909         $parent = ""; 
    910         for($i = 0; $i < $max; $i++) { 
    911             if($arrData[$i][$id_name] == $child) { 
    912                 $parent = $arrData[$i][$pid_name]; 
    913                 break; 
    914             } 
    915         } 
     887    function sfGetParentsArraySub($table, $pid_name, $id_name, $child) { 
     888        $objQuery =& SC_Query_Ex::getSingletonInstance(); 
     889        $parent = $objQuery->get($pid_name, $table, "$id_name = ?", $child); 
    916890        return $parent; 
    917891    } 
     
    926900        // 子カテゴリIDの取得 
    927901        $arrRet = SC_Helper_DB_Ex::sfGetChildrenArray("dtb_category", "parent_category_id", "category_id", $category_id); 
    928         $tmp_where = ""; 
    929         foreach ($arrRet as $val) { 
    930             if($tmp_where == "") { 
    931                 $tmp_where.= "category_id IN ( ?"; 
    932             } else { 
    933                 $tmp_where.= ",? "; 
    934             } 
    935             $arrval[] = $val; 
    936         } 
    937         $tmp_where.= " ) "; 
    938         return array($tmp_where, $arrval); 
     902 
     903        $where = "category_id IN (" . implode(',', array_fill(0, count($arrRet), '?')) . ")"; 
     904 
     905        return array($where, $arrRet); 
    939906    } 
    940907 
Note: See TracChangeset for help on using the changeset viewer.