mirror of
https://gitlab.com/hashborgir/d2tools.git
synced 2025-10-13 16:34:23 -05:00
In memory data refactor, less queries, cube/unique doc backend working fast
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
<?php
|
||||
|
||||
class D2ItemData {
|
||||
|
||||
public $strings;
|
||||
|
||||
public function uniqueItems($index, $doc = FALSE) {
|
||||
// This is where we get props for each item
|
||||
$sql = "SELECT * FROM `uniqueitems` WHERE `enabled`='1' AND `index`=\"$index\"";
|
||||
$sql = "SELECT * FROM uniqueitems WHERE enabled='1' AND `index`=?";
|
||||
|
||||
$res = (PDO_FetchRow($sql));
|
||||
$res = (PDO_FetchRow($sql, [$index]));
|
||||
|
||||
/*
|
||||
*
|
||||
@@ -26,14 +28,14 @@ class D2ItemData {
|
||||
// if no invfile, get from other tables
|
||||
// try to get from armor, weapons, misc
|
||||
|
||||
$sql = "SELECT invfile FROM armor WHERE code='{$res['code']}'";
|
||||
$invfile[] = PDO_FetchRow($sql);
|
||||
$sql = "SELECT invfile FROM armor WHERE code=?";
|
||||
$invfile[] = PDO_FetchRow($sql, [$res['code']]);
|
||||
|
||||
$sql = "SELECT invfile FROM weapons WHERE code='{$res['code']}'";
|
||||
$invfile[] = PDO_FetchRow($sql);
|
||||
$sql = "SELECT invfile FROM weapons WHERE code=?";
|
||||
$invfile[] = PDO_FetchRow($sql, [$res['code']]);
|
||||
|
||||
$sql = "SELECT invfile FROM misc WHERE code='{$res['code']}'";
|
||||
$invfile[] = PDO_FetchRow($sql);
|
||||
$sql = "SELECT invfile FROM misc WHERE code=?";
|
||||
$invfile[] = PDO_FetchRow($sql, [$res['code']]);
|
||||
|
||||
$invfile = array_filter($invfile);
|
||||
|
||||
@@ -41,17 +43,17 @@ class D2ItemData {
|
||||
$x[] = $i;
|
||||
}
|
||||
|
||||
if(!empty($x[0])){
|
||||
if (!empty($x[0])) {
|
||||
$x[0] = array_filter($x[0]);
|
||||
}
|
||||
$invClean = $x[0];
|
||||
if (!empty($invClean)){
|
||||
if (!empty($invClean)) {
|
||||
$return = array_merge($res, $invClean);
|
||||
} else {
|
||||
$return = $res;
|
||||
}
|
||||
|
||||
$return = array_merge($res, $invClean);
|
||||
//$return = array_merge($res, $invClean);
|
||||
} else {
|
||||
$return = $res;
|
||||
}
|
||||
@@ -105,19 +107,20 @@ class D2ItemData {
|
||||
//
|
||||
//
|
||||
// ( Also need func1 and val1 for each prop )
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
//
|
||||
// for each prop, get stat
|
||||
$counter = 1;
|
||||
foreach ($props as $key => $val) {
|
||||
// val = Prop1,Prop2 etc.
|
||||
// for each propr, get all 7 stats in ISC
|
||||
$sql = "SELECT stat1 FROM `properties` WHERE `code` = '{$val['prop' . $counter]}'";
|
||||
$props[$key]['stat'] = PDO_FetchRow($sql);
|
||||
|
||||
// for now only get stat1, and for else, use dgrp
|
||||
|
||||
$sql = "SELECT stat1 FROM properties WHERE code = ?";
|
||||
$props[$key]['stat'] = PDO_FetchRow($sql, [$val['prop' . $counter]]);
|
||||
|
||||
if (!empty($props[$key]['stat'])){
|
||||
if (!empty($props[$key]['stat'])) {
|
||||
$props[$key]['stat'] = array_filter($props[$key]['stat']);
|
||||
}
|
||||
|
||||
@@ -126,8 +129,8 @@ class D2ItemData {
|
||||
|
||||
|
||||
//ddump($props);
|
||||
|
||||
$counter = 1;
|
||||
|
||||
$counter = 1;
|
||||
//each stat now goes into getIscStrings
|
||||
foreach ($props as $k => $v) {
|
||||
//ddump($v);
|
||||
@@ -140,8 +143,6 @@ $counter = 1;
|
||||
|
||||
$counter = 1;
|
||||
foreach ($props as $k => $v) { // for each property Prop1 Prop2
|
||||
|
||||
|
||||
// $sql = "SELECT val$counter,func$counter FROM `properties` WHERE `code`=\"{$return['prop' . $counter]}\"";
|
||||
// $funcval = PDO_FetchRow($sql);
|
||||
//
|
||||
@@ -149,14 +150,19 @@ $counter = 1;
|
||||
$params = [
|
||||
'string1' => $v['desc']['string1'],
|
||||
'string2' => $v['desc']['string2'],
|
||||
'gstring1' => $v['desc']['gstring1'],
|
||||
'gstring2' => $v['desc']['gstring2'],
|
||||
'descfunc' => $v['desc']['descfunc'],
|
||||
'descval' => $v['desc']['descval'],
|
||||
'dgrp' => $v['desc']['dgrp'],
|
||||
'dgrpfunc' => $v['desc']['dgrpfunc'],
|
||||
'dgrpval' => $v['desc']['dgrpval'],
|
||||
"prop" => $return['prop' . $counter],
|
||||
"par" => $return['par' . $counter],
|
||||
"min" => $return['min' . $counter],
|
||||
"max" => $return['max' . $counter],
|
||||
// "val1" => $funcval['val1'],
|
||||
// "func1" => $funcval['func1']
|
||||
// "val1" => $funcval['val1'],
|
||||
// "func1" => $funcval['func1']
|
||||
// 'item' => $return
|
||||
];
|
||||
|
||||
@@ -174,37 +180,34 @@ $counter = 1;
|
||||
|
||||
$return['props'] = $props;
|
||||
|
||||
$sqlArmor = "SELECT * FROM armor WHERE code='{$res['code']}'";
|
||||
$sqlMisc = "SELECT * FROM misc WHERE code='{$res['code']}'";
|
||||
$sqlWeapons = "SELECT * FROM weapons WHERE code='{$res['code']}'";
|
||||
$sqlArmor = "SELECT * FROM armor WHERE code=?";
|
||||
$sqlMisc = "SELECT * FROM misc WHERE code=?";
|
||||
$sqlWeapons = "SELECT * FROM weapons WHERE code=?";
|
||||
|
||||
$baseItemInfo = PDO_FetchRow($sqlArmor);
|
||||
$baseItemInfo = PDO_FetchRow($sqlArmor, [$res['code']]);
|
||||
$uTable = "armor";
|
||||
|
||||
if (empty($baseItemInfo)) {
|
||||
$baseItemInfo = PDO_FetchRow($sqlMisc);
|
||||
$baseItemInfo = PDO_FetchRow($sqlMisc, [$res['code']]);
|
||||
}
|
||||
if (empty($baseItemInfo)) {
|
||||
$baseItemInfo = PDO_FetchRow($sqlWeapons);
|
||||
$baseItemInfo = PDO_FetchRow($sqlWeapons, [$res['code']]);
|
||||
}
|
||||
|
||||
$return['baseItemInfo'] = $baseItemInfo;
|
||||
|
||||
if(!empty($baseItemInfo)){
|
||||
if (!empty($baseItemInfo)) {
|
||||
$return['baseItemInfo'] = array_filter($baseItemInfo);
|
||||
}
|
||||
|
||||
if(!$doc){
|
||||
if (!$doc) {
|
||||
header('Content-Type: application/json');
|
||||
return json_encode($return, JSON_INVALID_UTF8_IGNORE | JSON_PRETTY_PRINT);
|
||||
} else {
|
||||
return $return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// function getIscStringsX($iscStat) {
|
||||
//// $sql = "
|
||||
////SELECT s1.String as string1, s2.String as string2, descfunc, descval
|
||||
@@ -213,35 +216,35 @@ $counter = 1;
|
||||
//// LEFT JOIN strings AS `s2` ON `i`.DescStr2 = `s2`.`Key`
|
||||
//// WHERE `Stat` = '$iscStat'
|
||||
////";
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// $sql = "SELECT String as string1
|
||||
// FROM itemstatcost as i
|
||||
// LEFT JOIN strings AS `s` ON `i`.descstrpos = `s`.`Key`
|
||||
// WHERE `Stat` = '$iscStat'";
|
||||
// WHERE `Stat` = '$iscStat'";
|
||||
// $string1 = PDO_FetchOne($sql);
|
||||
//
|
||||
//
|
||||
// $sql = "SELECT String as string2
|
||||
// FROM itemstatcost as i
|
||||
// LEFT JOIN strings AS `s` ON `i`.DescStr2 = `s`.`Key`
|
||||
// WHERE `Stat` = '$iscStat'";
|
||||
// $string2 = PDO_FetchOne($sql);
|
||||
//
|
||||
//
|
||||
// $sql = "SELECT descfunc
|
||||
// FROM itemstatcost as i
|
||||
// LEFT JOIN strings AS `s` ON `i`.descstrpos = `s`.`Key`
|
||||
// WHERE `Stat` = '$iscStat'";
|
||||
// $descfunc = PDO_FetchOne($sql);
|
||||
//
|
||||
//
|
||||
// $sql = "SELECT descval
|
||||
// FROM itemstatcost as i
|
||||
// LEFT JOIN strings AS `s` ON `i`.descstrpos = `s`.`Key`
|
||||
// WHERE `Stat` = '$iscStat'";
|
||||
// $descval = PDO_FetchOne($sql);
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// //ddump();
|
||||
//
|
||||
//
|
||||
// return ["string1"=>$string1, "string2"=>$string2, "descfunc"=>$descfunc, "descval"=>$descval];
|
||||
// }
|
||||
//
|
||||
@@ -278,48 +281,66 @@ $counter = 1;
|
||||
//AS descval
|
||||
//";
|
||||
//
|
||||
//
|
||||
//
|
||||
// return PDO_FetchRow($sql);
|
||||
// }
|
||||
|
||||
|
||||
|
||||
public function getIscStrings($iscStat) {
|
||||
$sql = "SELECT p.`code` as prop,
|
||||
p.stat1,
|
||||
i.descstrpos,
|
||||
i.descstr2,
|
||||
i.descfunc,
|
||||
i.descval,
|
||||
s1.String as string1,
|
||||
s2.String as string2
|
||||
FROM properties as p
|
||||
LEFT JOIN itemstatcost as i
|
||||
ON p.stat1 = i.Stat
|
||||
LEFT JOIN strings as s1
|
||||
ON i.descstrpos = s1.Key
|
||||
LEFT JOIN strings as s2
|
||||
ON i.descstr2 = s2.Key
|
||||
WHERE p.code = \"$iscStat\"
|
||||
|
||||
|
||||
if (empty($this->strings)){
|
||||
$this->getStrings();
|
||||
}
|
||||
|
||||
return ($this->strings[$iscStat]);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function getStrings() {
|
||||
$sql = "
|
||||
SELECT p.`code` as prop,
|
||||
p.stat1,
|
||||
i.descstrpos,
|
||||
i.descstr2,
|
||||
i.descfunc,
|
||||
i.descval,
|
||||
i.dgrp,
|
||||
i.dgrpfunc,
|
||||
i.dgrpval,
|
||||
i.dgrpstrpos,
|
||||
i.dgrpstrneg,
|
||||
s1.String as string1,
|
||||
s2.String as string2,
|
||||
s3.String as gstring1,
|
||||
s4.String as gstring2
|
||||
FROM properties as p
|
||||
|
||||
LEFT JOIN itemstatcost as i
|
||||
ON p.stat1 = i.Stat
|
||||
|
||||
LEFT JOIN strings as s1
|
||||
ON i.descstrpos = s1.Key
|
||||
LEFT JOIN strings as s2
|
||||
ON i.descstr2 = s2.Key
|
||||
|
||||
LEFT JOIN strings as s3
|
||||
ON i.dgrpstrpos = s3.Key
|
||||
LEFT JOIN strings as s4
|
||||
ON i.dgrpstr2= s4.Key
|
||||
";
|
||||
|
||||
|
||||
return PDO_FetchRow($sql);
|
||||
// where p.code = iscstat
|
||||
|
||||
$strings = PDO_FetchAll($sql);
|
||||
|
||||
|
||||
//var_dump($strings);
|
||||
foreach($strings as $k => $v){
|
||||
$this->strings[$v['prop']] = $v;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public function genDoc($itemData){
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@@ -268,6 +268,15 @@ class D2ItemDesc {
|
||||
|
||||
*/
|
||||
|
||||
public function __construct() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public function getDesc($params = []) {
|
||||
if (empty($params))
|
||||
return false;
|
||||
@@ -280,6 +289,14 @@ class D2ItemDesc {
|
||||
$par = $params['par'];
|
||||
$min = (int) $params['min'];
|
||||
$v = $par;
|
||||
|
||||
// if ($params['dgrp']){
|
||||
// $s1 = $params['gstring1'];
|
||||
// $s2 = $params['gstring2'];
|
||||
// $params['descfunc'] = $params['dgrpfunc'];
|
||||
// $params['descval'] = $params['dgrpval'];
|
||||
// }
|
||||
|
||||
|
||||
if (empty($par)) {
|
||||
$v = $min;
|
||||
@@ -291,11 +308,13 @@ class D2ItemDesc {
|
||||
$max = '';
|
||||
}
|
||||
|
||||
foreach ($this->skilltabs as $s) {
|
||||
$sql = "SELECT `String` FROM `strings` WHERE `Key`='$s'";
|
||||
$this->skilltabsDesc[] = PDO_FetchRow($sql);
|
||||
if (empty($this->skilltabsDesc)){
|
||||
|
||||
foreach ($this->skilltabs as $s) {
|
||||
$sql = "SELECT String FROM strings WHERE Key=?";
|
||||
$this->skilltabsDesc[] = PDO_FetchRow($sql, [$s]);
|
||||
}
|
||||
}
|
||||
|
||||
//ddump($this->skilltabsDescClean);
|
||||
|
||||
/*
|
||||
|
Reference in New Issue
Block a user