diff options
| author | Bharat Mediratta <bharat@menalto.com> | 2009-07-27 15:17:14 -0700 | 
|---|---|---|
| committer | Bharat Mediratta <bharat@menalto.com> | 2009-07-27 15:17:14 -0700 | 
| commit | 7efb4b4cdfba4c0280b18d1980cd8ad011360b87 (patch) | |
| tree | d4b274464b21405f435382faac427169e26e3d0d /modules/gallery/models | |
| parent | b3fe70e654c1519f8f1d54a80f99d0af7a8f2e49 (diff) | |
Remove the unnecessary ORDER BY on $this->sort_column in
get_position(), and instead apply an ORDER BY on `id` in the 2nd query
so that we have stability among the equal elements.  This should
result in cheaper (and more sensible) queries.
Diffstat (limited to 'modules/gallery/models')
| -rw-r--r-- | modules/gallery/models/item.php | 11 | 
1 files changed, 6 insertions, 5 deletions
| diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index 038e11fb..dcbee991 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -399,10 +399,10 @@ class Item_Model extends ORM_MPTT {      $db = Database::instance();      $position = $db->query("        SELECT COUNT(*) AS position FROM {items} -      WHERE parent_id = {$this->id} +      WHERE `parent_id` = {$this->id}          AND `{$this->sort_column}` $comp (SELECT `{$this->sort_column}` -                                          FROM {items} WHERE id = $child_id) -      ORDER BY `{$this->sort_column}` {$this->sort_order}")->current()->position; +                                          FROM {items} WHERE `id` = $child_id)") +      ->current()->position;      // We stopped short of our target value in the sort (notice that we're using a < comparator      // above) because it's possible that we have duplicate values in the sort column.  An @@ -414,9 +414,10 @@ class Item_Model extends ORM_MPTT {      // our base value.      $result = $db->query("        SELECT id FROM {items} -      WHERE parent_id = {$this->id} +      WHERE `parent_id` = {$this->id}          AND `{$this->sort_column}` = (SELECT `{$this->sort_column}` -                                      FROM {items} WHERE id = $child_id)"); +                                      FROM {items} WHERE `id` = $child_id) +      ORDER BY `id` ASC");      foreach ($result as $row) {        $position++;        if ($row->id == $child_id) { | 
