ここの情報は古いです。ご理解頂いた上でお取り扱いください。

Changeset 10088


Ignore:
Timestamp:
Jan 11, 2009, 4:17:07 PM (11 years ago)
Author:
ogawa
Message:

reduced the number of SQL queries by fetching all results at a time

Location:
OpenPNE3/trunk/lib/model
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • OpenPNE3/trunk/lib/model/HomeWidgetConfigPeer.php

    r10003 r10088  
    1111class HomeWidgetConfigPeer extends BaseHomeWidgetConfigPeer
    1212{
     13  static protected $results;
     14
    1315  static public function retrieveByWidgetIdAndName($widgetId, $name)
    1416  {
    15     $c = new Criteria();
    16     $c->add(HomeWidgetConfigPeer::HOME_WIDGET_ID, $widgetId);
    17     $c->add(HomeWidgetConfigPeer::NAME, $name);
    18     return self::doSelectOne($c);
     17    $results = self::getResults();
     18
     19    return (isset($results[$widgetId][$name])) ? $results[$widgetId][$name] : null;
     20  }
     21
     22  static protected function getResults()
     23  {
     24    if (is_null(self::$results))
     25    {
     26      self::$results = array();
     27      foreach (self::doSelect(new Criteria()) as $object)
     28      {
     29        self::$results[$object->getHomeWidgetId()][$object->getName()] = $object;
     30      }
     31    }
     32
     33    return self::$results;
    1934  }
    2035}
  • OpenPNE3/trunk/lib/model/HomeWidgetPeer.php

    r10003 r10088  
    1111class HomeWidgetPeer extends BaseHomeWidgetPeer
    1212{
     13  static protected $results;
     14
    1315  static public function retrieveTopWidgets()
    1416  {
     
    4345  static public function retrieveByType($type)
    4446  {
    45     $c = new Criteria();
    46     $c->add(self::TYPE, $type);
    47     $c->addAscendingOrderByColumn(self::SORT_ORDER);
    48     return self::doSelect($c);
     47    $results = self::getResults();
     48
     49    return (isset($results[$type])) ? $results[$type] : null;
    4950  }
    5051
     
    6667    return $result;
    6768  }
     69
     70  static protected function getResults()
     71  {
     72    if (is_null(self::$results))
     73    {
     74      $criteria = new Criteria();
     75      $criteria->addAscendingOrderByColumn(self::SORT_ORDER);
     76
     77      self::$results = array();
     78      foreach (self::doSelect($criteria) as $object)
     79      {
     80        self::$results[$object->getType()][] = $object;
     81      }
     82    }
     83
     84    return self::$results;
     85  }
    6886}
  • OpenPNE3/trunk/lib/model/MemberConfigPeer.php

    r10003 r10088  
    1818class MemberConfigPeer extends BaseMemberConfigPeer
    1919{
     20  static protected $results;
     21
    2022  public static function retrieveByNameAndMemberId($name, $memberId)
    2123  {
    22     $c = new Criteria();
    23     $c->add(self::NAME, $name);
    24     $c->add(self::MEMBER_ID, $memberId);
     24    $results = self::getResultsByMemberId($memberId);
    2525
    26     $result = self::doSelectOne($c);
    27 
    28     return $result;
     26    return (isset($results[$name])) ? $results[$name] : null;
    2927  }
    3028
     
    6462    }
    6563  }
     64
     65  static protected function getResultsByMemberId($memberId)
     66  {
     67    if (is_null(self::$results[$memberId]))
     68    {
     69      $criteria = new Criteria();
     70      $criteria->add(self::MEMBER_ID, $memberId);
     71
     72      self::$results[$memberId] = array();
     73      foreach (self::doSelect($criteria) as $object)
     74      {
     75        self::$results[$memberId][$object->getName()] = $object;
     76      }
     77    }
     78
     79    return self::$results[$memberId];
     80  }
    6681}
Note: See TracChangeset for help on using the changeset viewer.