From acb360d015b74c86c3e14d09fb4163f46f27d699 Mon Sep 17 00:00:00 2001 From: Shadez Date: Fri, 14 Jan 2011 22:53:39 +0800 Subject: [PATCH] [451] Store `data` field in Characters class. This will decrease amount of SQL queries to characters DB. --- includes/classes/class.characters.php | 31 +++++++++++++++++++++------ includes/revision_nr.php | 2 +- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/includes/classes/class.characters.php b/includes/classes/class.characters.php index 153e4b4ac..78ac2d328 100644 --- a/includes/classes/class.characters.php +++ b/includes/classes/class.characters.php @@ -3,7 +3,7 @@ /** * @package World of Warcraft Armory * @version Release 4.50 - * @revision 450 + * @revision 451 * @copyright (c) 2009-2011 Shadez * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @@ -251,6 +251,11 @@ **/ private $feed_data = array(); + /** + * Character data + **/ + private $char_data = array(); + /** * Init character, load data from DB, checks for requirements, etc. * @category Characters class @@ -345,6 +350,8 @@ public function BuildCharacter($name, $realmId = 1, $full = true, $initialBuild unset($player_data); return false; } + $this->char_data = $this->db->selectCell("SELECT `data` FROM `armory_character_stats` WHERE `guid` = %d LIMIT 1", $player_data['guid']); + $this->HandleCharacterData(); } // Can we display this character? $gmLevel = false; @@ -495,6 +502,21 @@ private function HandleChosenTitleInfo() { return true; } + private function HandleCharacterData() { + if(!$this->char_data) { + return false; + } + if(is_array($this->char_data)) { + // Already converted. + return true; + } + $this->char_data = explode(' ', $this->char_data); + if(!is_array($this->char_data) || !isset($this->char_data[1])) { + Armory::Log()->writeError('%s : unable to convert $this->char_data from string to array!', __METHOD__); + } + return true; + } + /** * Checks current player (loaded or not). * @category Characters class @@ -1446,12 +1468,7 @@ public function GetDataField($fieldNum, $guid = null) { Armory::Log()->writeError('%s : guid not provided', __METHOD__); return false; } - $fieldNum++; - $qData = $this->db->selectCell(" - SELECT CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(`data`, ' ', %d), ' ', '-1') AS UNSIGNED) - FROM `armory_character_stats` - WHERE `guid`=%d", $fieldNum, $guid); - return $qData; + return (isset($this->char_data[$fieldNum])) ? $this->char_data[$fieldNum] : 0; } /** diff --git a/includes/revision_nr.php b/includes/revision_nr.php index 467f6fac5..9fff67028 100644 --- a/includes/revision_nr.php +++ b/includes/revision_nr.php @@ -1,5 +1,5 @@ \ No newline at end of file