OSDN Git Service

ORDERによるSQL負荷回避修正
authorCake <cake_67@users.sourceforge.jp>
Tue, 13 Jul 2010 06:05:36 +0000 (15:05 +0900)
committerCake <cake_67@users.sourceforge.jp>
Tue, 13 Jul 2010 06:05:36 +0000 (15:05 +0900)
app/controllers/app_controller.php
app/controllers/characters_controller.php
app/controllers/profile_selects_controller.php
app/controllers/profile_table_statics_controller.php
app/controllers/profile_tables_controller.php
app/libs/core_plus.php
app/models/profile.php
app/models/profile_table.php
app/models/system.php

index 270fbc7..ecb98a8 100644 (file)
@@ -498,41 +498,76 @@ class AppController extends Controller
        }
        function __restore_html_profile($data) {
                if (isset($data['ProfileSelect']) && !empty($data['ProfileSelect'])) {
-                       $data = $this->_restore_html_profile_select($data);
+                       $data['ProfileSelect'] = $this->_restore_html_profile_select($data['ProfileSelect']);
                }
                if (isset($data['ProfileTable']) && !empty($data['ProfileTable'])) {
-                       $data = $this->_restore_html_profile_table($data);
+                       $data['ProfileTable'] = $this->_restore_html_profile_table($data['ProfileTable']);
                }
                if (isset($data['ProfileTableStatic']) && !empty($data['ProfileTableStatic'])) {
-                       $data = $this->_restore_html_profile_table_static($data);
+                       $data['ProfileTableStatic'] = $this->_restore_html_profile_table_static($data['ProfileTableStatic']);
                }
 
                return $data;
        }
        function _restore_html_profile_select($data) {
-               foreach ($data['ProfileSelect'] as $k => $v) {
-                       if (isset($data['ProfileSelect'][$k]['value'])  && !empty($data['ProfileSelect'][$k]['value'])) {
-                               $data['ProfileSelect'][$k]['value'] = $this->{$this->modelClass}->restore_html($v['value'], false, false, false);
+               $sort_order = array();
+               foreach ($data as $k => $v) {
+                       if (isset($v['value'])  && !empty($v['value'])) {
+                               $data[$k]['value'] = $this->{$this->modelClass}->restore_html($v['value'], false, false, false);
+                       }
+
+                       if (isset($v['sort_order'])  && !empty($v['sort_order'])) {
+                               $sort_order[$k] = $v['sort_order'];
+                       } else {
+                               $sort_order[$k] = 0;
                        }
                }
 
+               $data = $this->sort4sort_order($data, $sort_order);
+
                return $data;
        }
        function _restore_html_profile_table($data) {
-               foreach ($data['ProfileTable'] as $k => $v) {
-                       if (isset($data['ProfileTable'][$k]['value'])  && !empty($data['ProfileTable'][$k]['value'])) {
-                               $data['ProfileTable'][$k]['value'] = $this->{$this->modelClass}->restore_html($v['value'], false, false, false);
+               foreach ($data as $k => $v) {
+                       if (isset($v['value'])  && !empty($v['value'])) {
+                               $data[$k]['value'] = $this->{$this->modelClass}->restore_html($v['value'], false, false, false);
+                       }
+
+                       if (isset($v['sort_order'])  && !empty($v['sort_order'])) {
+                               $sort_order[$k] = $v['sort_order'];
+                       } else {
+                               $sort_order[$k] = 0;
                        }
                }
 
+               $data = $this->sort4sort_order($data, $sort_order);
+
                return $data;
        }
        function _restore_html_profile_table_static($data) {
-               foreach ($data['ProfileTableStatic'] as $k => $v) {
-                       if (isset($data['ProfileTableStatic'][$k]['title'])  && !empty($data['ProfileTableStatic'][$k]['title'])) {
+               foreach ($data as $k => $v) {
+                       if (isset($v['title'])  && !empty($v['title'])) {
                                $data['ProfileTableStatic'][$k]['title'] = $this->{$this->modelClass}->restore_html($v['title'], false, false, false);
                        }
+
+                       if (isset($v['sort_order'])  && !empty($v['sort_order'])) {
+                               $sort_order[$k] = $v['sort_order'];
+                       } else {
+                               $sort_order[$k] = 0;
+                       }
+               }
+
+               $data = $this->sort4sort_order($data, $sort_order);
+
+               return $data;
+       }
+
+       function sort4sort_order($data, $sort_order)
+       {
+               if (empty($data) || empty($sort_order)) {
+                       return $data;
                }
+               array_multisort($sort_order, SORT_ASC, $data);
 
                return $data;
        }
index a6d7021..8617532 100644 (file)
@@ -113,7 +113,7 @@ class CharactersController extends AppController {
                $this->Character->System->Profile->hasMany['CharactersHasProfile']['fields'] = '';
                unset($this->Character->hasMany['CharacterProfileArchive']);
 
-               $character = $this->_get_character($id, array(), false, array('System' => 'Ptofile'));
+               $character = $this->_get_character($id, array(), false);
                if (!$this->isOwner($character['Character'], $this->user_id)) {
                        $this->Session->setFlash(__('No Permission', true));
                        $this->redirect(array('action'=>'index'));
@@ -452,7 +452,7 @@ class CharactersController extends AppController {
                $this->Character->System->Profile->hasMany['CharactersHasProfile']['fields'] = '';
                unset($this->Character->hasMany['CharacterProfileArchive']);
 
-               $character = $this->_get_character($id, array(), true, array('System' => 'Profile'));
+               $character = $this->_get_character($id, array(), true);
                if (!$character) {
                        $this->Session->setFlash(__('No Character', true));
                        $this->redirect(array('action'=>'index'));
index 8054ca0..9d191e4 100644 (file)
@@ -18,7 +18,7 @@ class ProfileSelectsController extends AppController {
 
        function admin_listview($profile_id = null) {
 
-               $profile = $this->get_profile4profile_id ($profile_id);
+               $profile = $this->get_profile4profile_id($profile_id);
 
                $this->set('profile', $profile);
        }
@@ -165,6 +165,17 @@ class ProfileSelectsController extends AppController {
                ));
 
                if ($this->check_profile_type($profile)) {
+
+               foreach ($profile['ProfileSelect'] as $k => $v) {
+
+                       if (isset($v['sort_order'])  && !empty($v['sort_order'])) {
+                               $sort_order[$k] = $v['sort_order'];
+                       } else {
+                               $sort_order[$k] = 0;
+                       }
+               }
+               $profile['ProfileSelect'] = $this->sort4sort_order($profile['ProfileSelect'], $sort_order);
+
                        return $profile;
                }
        }
index 7f46646..f13fde9 100644 (file)
@@ -40,6 +40,15 @@ class ProfileTableStaticsController extends AppController {
                        $this->redirect(array('controller'=>'systems', 'action'=>'admin_index'));
                }
 
+               foreach ($profileTable['ProfileTableStatic'] as $k => $v) {
+                       if (isset($v['sort_order'])  && !empty($v['sort_order'])) {
+                               $sort_order[$k] = $v['sort_order'];
+                       } else {
+                               $sort_order[$k] = 0;
+                       }
+               }
+               $profileTable['ProfileTableStatic'] = $this->sort4sort_order($profileTable['ProfileTableStatic'], $sort_order);
+
                if (!empty($this->data)) {
                        // POSTデータ処理
                        $this->_set_new_profile_table_static($profileTable['ProfileTable']['id']);
@@ -117,11 +126,11 @@ class ProfileTableStaticsController extends AppController {
                                continue;
                        }
 
-                               $this->data['ProfileTableStatic'][$k]['profile_table_id'] = $profile_table_id;
+                       $this->data['ProfileTableStatic'][$k]['profile_table_id'] = $profile_table_id;
 
-                               if (empty($v['sort_order'])) {
-                                       $this->data['ProfileTableStatic'][$k]['sort_order'] = 0;
-                               }
+                       if (empty($v['sort_order'])) {
+                               $this->data['ProfileTableStatic'][$k]['sort_order'] = 0;
+                       }
                }
                unset($this->data['ProfileTableStatic']['__Token']);
 
index 5dfa901..ccdef51 100644 (file)
@@ -178,6 +178,16 @@ class ProfileTablesController extends AppController {
                ));
 
                if ($this->check_profile_type($profile)) {
+                       foreach ($profile['ProfileTable'] as $k => $v) {
+
+                               if (isset($v['sort_order'])  && !empty($v['sort_order'])) {
+                                       $sort_order[$k] = $v['sort_order'];
+                               } else {
+                                       $sort_order[$k] = 0;
+                               }
+                       }
+                       $profile['ProfileTable'] = $this->sort4sort_order($profile['ProfileTable'], $sort_order);
+
                        return $profile;
                }
        }
index ee5c246..46ced82 100644 (file)
@@ -105,7 +105,7 @@ class CorePlus extends Object {
                                'SiteConfig.value',
                        ),
                        'recursive' => -1,
-                       'order' => array('SiteConfig.key_name' => 'asc'),
+//                     'order' => array('SiteConfig.key_name' => 'asc'), // MySQL Filesortの原因
                ));
 
                $site_configs = array();
index 32617be..446a4d2 100644 (file)
@@ -91,7 +91,7 @@ class Profile extends AppModel {
                        'dependent' => true,
                        'conditions' => '',
                        'fields' => '',
-                       'order' => array('ProfileSelect.sort_order' => 'asc'),
+//                     'order' => array('ProfileSelect.sort_order' => 'asc'), // Using filesortの原因
                        'limit' => '',
                        'offset' => '',
                        'exclusive' => '',
@@ -104,7 +104,7 @@ class Profile extends AppModel {
                        'dependent' => true,
                        'conditions' => '',
                        'fields' => '',
-                       'order' => array('ProfileTable.sort_order' => 'asc'),
+//                     'order' => array('ProfileTable.sort_order' => 'asc'),
                        'limit' => '',
                        'offset' => '',
                        'exclusive' => '',
index 402fb72..662f84a 100644 (file)
@@ -71,7 +71,7 @@ class ProfileTable extends AppModel {
                        'dependent' => true,
                        'conditions' => '',
                        'fields' => '',
-                       'order' => array('ProfileTableStatic.sort_order' => 'asc'),
+//                     'order' => array('ProfileTableStatic.sort_order' => 'asc'),
                        'limit' => '',
                        'offset' => '',
                        'finderQuery' => '',
index 7624683..5b7d81e 100644 (file)
@@ -116,7 +116,7 @@ class System extends AppModel {
                                'Profile.key_name',
                                'Profile.profile_type',
                        ),
-                       'order' => 'Profile.sort_order ASC',
+//                     'order' => 'Profile.sort_order ASC',
                ),
                // システムイメージ
                'Attachment' => array(