In memory data refactor, less queries, cube/unique doc backend working fast

This commit is contained in:
color.diff=auto 2021-05-12 19:00:56 -06:00
parent ca04aa615f
commit 5eced413cb
7 changed files with 15188 additions and 133 deletions

View File

@ -134,8 +134,8 @@ WHERE `type` IS NOT NULL AND uniqueitems.`code`= $table.`code` AND $table.`code`
*/ */
if ($cmd == 'search') { if ($cmd == 'search') {
$search = $_GET['search']; $search = $_GET['search'];
$sql = "SELECT * FROM uniqueitems WHERE `index` LIKE '%$search%' OR `code` LIKE '%$search%' AND `enabled`=1 ORDER BY `index`"; $sql = "SELECT * FROM uniqueitems WHERE `index` LIKE '%?%' OR code LIKE '%?%' AND enabled=1 ORDER BY `index`";
$res = PDO_FetchAll($sql); $res = PDO_FetchAll($sql,[$search, $search]);
$html = ''; $html = '';
foreach ($res as $r) { foreach ($res as $r) {
if ($sort == 'index') { if ($sort == 'index') {
@ -160,10 +160,10 @@ if ($cmd == 'getString') {
$prop = $_GET['prop']; $prop = $_GET['prop'];
$sql = "SELECT stat1,stat2,stat3,stat4,stat5,stat6,stat7 FROM `properties` WHERE `code` = '$prop'"; $sql = "SELECT stat1,stat2,stat3,stat4,stat5,stat6,stat7 FROM properties WHERE code = ?";
$stat = array_filter(PDO_FetchRow($sql)); $stat = array_filter(PDO_FetchRow($sql, [$prop]));
$s = array_filter($idata->getIscStrings($stat['stat1'])); $s = array_filter($idata->getIscStrings($prop));
// now combine isc strings with par, min, max // now combine isc strings with par, min, max

File diff suppressed because one or more lines are too long

14927
docs/Ironman/uniqueitems.html Normal file

File diff suppressed because it is too large Load Diff

View File

@ -123,7 +123,25 @@ $htmltop = <<<EOT
text-align: $align; text-align: $align;
font-family: Lato; font-family: Lato;
} }
.item {
text-align: left;
position:relative;
right:0px;
}
.item_desc {
height: 600px;
width: 620px;
position: relative;
left: 0px;
top: 0px;
text-align: center;
padding: 10px;
text-transform: uppercase;
}
.item_stats{ .item_stats{
width: auto; width: auto;
@ -163,7 +181,7 @@ $htmltop = <<<EOT
$(document).ready(function() { $(document).ready(function() {
// $('.cubetable').dataTable(); $('.cubetable').dataTable();
} ); } );
@ -201,8 +219,8 @@ EOT;
* *
*/ */
$dir = getcwd() . "/docs/{$_SESSION['modname']}"; $dir = getcwd() . "/docs/{$_SESSION['modname']}";
mkdir($dir, 0777, true); mkdir($dir, 0777, true);
if ($cmd == "genDocUniqueItems") { if ($cmd == "genDocUniqueItems") {
// grab unique item index only (to save on memory) // grab unique item index only (to save on memory)
@ -369,7 +387,7 @@ if ($cmd == "genDocCube") {
body{ body{
background: white; background: white;
color: black; color: black;
font-family: ExocetLight; font-family: ExocetHeavy;
text-transform: uppercase; text-transform: uppercase;
} }
@ -411,16 +429,36 @@ if ($cmd == "genDocCube") {
} }
.desc { .desc {
width: 25%; width: 200px;
font-family: ExocetHeavy; font-family: ExocetHeavy;
font-size: 1.25em; font-size: 1.25em;
text-transform: uppercase;
background: #111;
} }
.input1,.input3,.input5,.input7{
background: #444;
}
.input2, .input4, .input6 {
background: #333;
}
.output1{
background: #222;
}
.output2 {
background: #222;
}
.output3 {
background: #222;
}
td { td {
width: auto;
height: 240px;
text-align: center; text-align: center;
vertical-align: middle; vertical-align: middle;
padding: 10px; padding: 10px;
} }
</style> </style>
EOT; EOT;
@ -493,7 +531,11 @@ EOT;
*/ */
foreach ($res as $r) { foreach ($res as $r) {
$desc = $r['description']; $desc = str_replace('+', '<br>+<br>', $r['description']);
$desc = str_replace('->', '<br><span class="" style="color: gold;font-size:1.25em;">=<br>', $desc);
$desc .= "</span>";
//ddump($desc);
//var_dump($r); //var_dump($r);
// grab all inputs // grab all inputs
$input_codes = array_filter( $input_codes = array_filter(
@ -955,7 +997,7 @@ EOT;
$htmlFinal .= $tableBottom . $htmlbottom; $htmlFinal .= $tableBottom . $htmlbottom;
file_put_contents("$dir/cubemain.html", $htmlFinal); file_put_contents("$dir/cubemain.html", $htmlFinal);
header("Location: /docs/{$_SESSION['modname']}/cubemain.html"); header("Location: docs/{$_SESSION['modname']}/cubemain.html");
} }
@ -965,28 +1007,45 @@ if ($cmd == "getIscStrings") {
// $sql = "SELECT p.`code` as prop, $sql = "
// p.stat1, SELECT p.`code` as prop,
// i.descstrpos, p.stat1,
// i.descstr2, i.descstrpos,
// i.descfunc, i.descstr2,
// i.descval, i.descfunc,
// s1.String as string1, i.descval,
// s2.String as string2 i.dgrp,
// FROM properties as p i.dgrpfunc,
// LEFT JOIN itemstatcost as i i.dgrpval,
// ON p.stat1 = i.Stat i.dgrpstrpos,
// LEFT JOIN strings as s1 i.dgrpstrneg,
// ON i.descstrpos = s1.Key s1.String as string1,
// LEFT JOIN strings as s2 s2.String as string2,
// ON i.descstr2 = s2.Key"; s3.String as gstring1,
// $res = PDO_FetchAll($sql); s4.String as gstring2
// FROM properties as p
// $isc = null;
// foreach ($res as $r) { LEFT JOIN itemstatcost as i
// $isc[$r['prop']] = $r; ON p.stat1 = i.Stat
// $isc[$r['prop']]['prop'] = $r['prop'];
// } 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
";
$res = PDO_FetchAll($sql);
$isc = null;
foreach ($res as $r) {
$isc[$r['prop']] = $r;
$isc[$r['prop']]['prop'] = $r['prop'];
}
var_dump($isc); var_dump($isc);

View File

@ -278,12 +278,3 @@ pre {outline: 1px solid #ccc; padding: 5px; margin: 5px; }
color: #4169E1; /* Magic color*/ color: #4169E1; /* Magic color*/
} }
.output1{
background: #222;
}
.output2 {
}
.output3 {
}

View File

@ -1,12 +1,14 @@
<?php <?php
class D2ItemData { class D2ItemData {
public $strings;
public function uniqueItems($index, $doc = FALSE) { public function uniqueItems($index, $doc = FALSE) {
// This is where we get props for each item // 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 // if no invfile, get from other tables
// try to get from armor, weapons, misc // try to get from armor, weapons, misc
$sql = "SELECT invfile FROM armor WHERE code='{$res['code']}'"; $sql = "SELECT invfile FROM armor WHERE code=?";
$invfile[] = PDO_FetchRow($sql); $invfile[] = PDO_FetchRow($sql, [$res['code']]);
$sql = "SELECT invfile FROM weapons WHERE code='{$res['code']}'"; $sql = "SELECT invfile FROM weapons WHERE code=?";
$invfile[] = PDO_FetchRow($sql); $invfile[] = PDO_FetchRow($sql, [$res['code']]);
$sql = "SELECT invfile FROM misc WHERE code='{$res['code']}'"; $sql = "SELECT invfile FROM misc WHERE code=?";
$invfile[] = PDO_FetchRow($sql); $invfile[] = PDO_FetchRow($sql, [$res['code']]);
$invfile = array_filter($invfile); $invfile = array_filter($invfile);
@ -41,17 +43,17 @@ class D2ItemData {
$x[] = $i; $x[] = $i;
} }
if(!empty($x[0])){ if (!empty($x[0])) {
$x[0] = array_filter($x[0]); $x[0] = array_filter($x[0]);
} }
$invClean = $x[0]; $invClean = $x[0];
if (!empty($invClean)){ if (!empty($invClean)) {
$return = array_merge($res, $invClean); $return = array_merge($res, $invClean);
} else { } else {
$return = $res; $return = $res;
} }
$return = array_merge($res, $invClean); //$return = array_merge($res, $invClean);
} else { } else {
$return = $res; $return = $res;
} }
@ -105,19 +107,20 @@ class D2ItemData {
// //
// //
// ( Also need func1 and val1 for each prop ) // ( Also need func1 and val1 for each prop )
//
//
//
// //
// for each prop, get stat // for each prop, get stat
$counter = 1; $counter = 1;
foreach ($props as $key => $val) { foreach ($props as $key => $val) {
// val = Prop1,Prop2 etc. // val = Prop1,Prop2 etc.
// for each propr, get all 7 stats in ISC // 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']); $props[$key]['stat'] = array_filter($props[$key]['stat']);
} }
@ -126,8 +129,8 @@ class D2ItemData {
//ddump($props); //ddump($props);
$counter = 1; $counter = 1;
//each stat now goes into getIscStrings //each stat now goes into getIscStrings
foreach ($props as $k => $v) { foreach ($props as $k => $v) {
//ddump($v); //ddump($v);
@ -140,8 +143,6 @@ $counter = 1;
$counter = 1; $counter = 1;
foreach ($props as $k => $v) { // for each property Prop1 Prop2 foreach ($props as $k => $v) { // for each property Prop1 Prop2
// $sql = "SELECT val$counter,func$counter FROM `properties` WHERE `code`=\"{$return['prop' . $counter]}\""; // $sql = "SELECT val$counter,func$counter FROM `properties` WHERE `code`=\"{$return['prop' . $counter]}\"";
// $funcval = PDO_FetchRow($sql); // $funcval = PDO_FetchRow($sql);
// //
@ -149,14 +150,19 @@ $counter = 1;
$params = [ $params = [
'string1' => $v['desc']['string1'], 'string1' => $v['desc']['string1'],
'string2' => $v['desc']['string2'], 'string2' => $v['desc']['string2'],
'gstring1' => $v['desc']['gstring1'],
'gstring2' => $v['desc']['gstring2'],
'descfunc' => $v['desc']['descfunc'], 'descfunc' => $v['desc']['descfunc'],
'descval' => $v['desc']['descval'], 'descval' => $v['desc']['descval'],
'dgrp' => $v['desc']['dgrp'],
'dgrpfunc' => $v['desc']['dgrpfunc'],
'dgrpval' => $v['desc']['dgrpval'],
"prop" => $return['prop' . $counter], "prop" => $return['prop' . $counter],
"par" => $return['par' . $counter], "par" => $return['par' . $counter],
"min" => $return['min' . $counter], "min" => $return['min' . $counter],
"max" => $return['max' . $counter], "max" => $return['max' . $counter],
// "val1" => $funcval['val1'], // "val1" => $funcval['val1'],
// "func1" => $funcval['func1'] // "func1" => $funcval['func1']
// 'item' => $return // 'item' => $return
]; ];
@ -174,37 +180,34 @@ $counter = 1;
$return['props'] = $props; $return['props'] = $props;
$sqlArmor = "SELECT * FROM armor WHERE code='{$res['code']}'"; $sqlArmor = "SELECT * FROM armor WHERE code=?";
$sqlMisc = "SELECT * FROM misc WHERE code='{$res['code']}'"; $sqlMisc = "SELECT * FROM misc WHERE code=?";
$sqlWeapons = "SELECT * FROM weapons WHERE code='{$res['code']}'"; $sqlWeapons = "SELECT * FROM weapons WHERE code=?";
$baseItemInfo = PDO_FetchRow($sqlArmor); $baseItemInfo = PDO_FetchRow($sqlArmor, [$res['code']]);
$uTable = "armor"; $uTable = "armor";
if (empty($baseItemInfo)) { if (empty($baseItemInfo)) {
$baseItemInfo = PDO_FetchRow($sqlMisc); $baseItemInfo = PDO_FetchRow($sqlMisc, [$res['code']]);
} }
if (empty($baseItemInfo)) { if (empty($baseItemInfo)) {
$baseItemInfo = PDO_FetchRow($sqlWeapons); $baseItemInfo = PDO_FetchRow($sqlWeapons, [$res['code']]);
} }
$return['baseItemInfo'] = $baseItemInfo; $return['baseItemInfo'] = $baseItemInfo;
if(!empty($baseItemInfo)){ if (!empty($baseItemInfo)) {
$return['baseItemInfo'] = array_filter($baseItemInfo); $return['baseItemInfo'] = array_filter($baseItemInfo);
} }
if(!$doc){ if (!$doc) {
header('Content-Type: application/json'); header('Content-Type: application/json');
return json_encode($return, JSON_INVALID_UTF8_IGNORE | JSON_PRETTY_PRINT); return json_encode($return, JSON_INVALID_UTF8_IGNORE | JSON_PRETTY_PRINT);
} else { } else {
return $return; return $return;
} }
} }
// function getIscStringsX($iscStat) { // function getIscStringsX($iscStat) {
//// $sql = " //// $sql = "
////SELECT s1.String as string1, s2.String as string2, descfunc, descval ////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` //// LEFT JOIN strings AS `s2` ON `i`.DescStr2 = `s2`.`Key`
//// WHERE `Stat` = '$iscStat' //// WHERE `Stat` = '$iscStat'
////"; ////";
// //
// //
// $sql = "SELECT String as string1 // $sql = "SELECT String as string1
// FROM itemstatcost as i // FROM itemstatcost as i
// LEFT JOIN strings AS `s` ON `i`.descstrpos = `s`.`Key` // LEFT JOIN strings AS `s` ON `i`.descstrpos = `s`.`Key`
// WHERE `Stat` = '$iscStat'"; // WHERE `Stat` = '$iscStat'";
// $string1 = PDO_FetchOne($sql); // $string1 = PDO_FetchOne($sql);
// //
// $sql = "SELECT String as string2 // $sql = "SELECT String as string2
// FROM itemstatcost as i // FROM itemstatcost as i
// LEFT JOIN strings AS `s` ON `i`.DescStr2 = `s`.`Key` // LEFT JOIN strings AS `s` ON `i`.DescStr2 = `s`.`Key`
// WHERE `Stat` = '$iscStat'"; // WHERE `Stat` = '$iscStat'";
// $string2 = PDO_FetchOne($sql); // $string2 = PDO_FetchOne($sql);
// //
// $sql = "SELECT descfunc // $sql = "SELECT descfunc
// FROM itemstatcost as i // FROM itemstatcost as i
// LEFT JOIN strings AS `s` ON `i`.descstrpos = `s`.`Key` // LEFT JOIN strings AS `s` ON `i`.descstrpos = `s`.`Key`
// WHERE `Stat` = '$iscStat'"; // WHERE `Stat` = '$iscStat'";
// $descfunc = PDO_FetchOne($sql); // $descfunc = PDO_FetchOne($sql);
// //
// $sql = "SELECT descval // $sql = "SELECT descval
// FROM itemstatcost as i // FROM itemstatcost as i
// LEFT JOIN strings AS `s` ON `i`.descstrpos = `s`.`Key` // LEFT JOIN strings AS `s` ON `i`.descstrpos = `s`.`Key`
// WHERE `Stat` = '$iscStat'"; // WHERE `Stat` = '$iscStat'";
// $descval = PDO_FetchOne($sql); // $descval = PDO_FetchOne($sql);
// //
// //
// //ddump(); // //ddump();
// //
// return ["string1"=>$string1, "string2"=>$string2, "descfunc"=>$descfunc, "descval"=>$descval]; // return ["string1"=>$string1, "string2"=>$string2, "descfunc"=>$descfunc, "descval"=>$descval];
// } // }
// //
@ -278,48 +281,66 @@ $counter = 1;
//AS descval //AS descval
//"; //";
// //
// //
// return PDO_FetchRow($sql); // return PDO_FetchRow($sql);
// } // }
public function getIscStrings($iscStat) { public function getIscStrings($iscStat) {
$sql = "SELECT p.`code` as prop,
p.stat1,
i.descstrpos, if (empty($this->strings)){
i.descstr2, $this->getStrings();
i.descfunc, }
i.descval,
s1.String as string1, return ($this->strings[$iscStat]);
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 public function getStrings() {
LEFT JOIN strings as s2 $sql = "
ON i.descstr2 = s2.Key SELECT p.`code` as prop,
WHERE p.code = \"$iscStat\" 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
"; ";
// where p.code = iscstat
return PDO_FetchRow($sql);
$strings = PDO_FetchAll($sql);
//var_dump($strings);
foreach($strings as $k => $v){
$this->strings[$v['prop']] = $v;
}
} }
public function genDoc($itemData){
}
} }

View File

@ -268,6 +268,15 @@ class D2ItemDesc {
*/ */
public function __construct() {
}
public function getDesc($params = []) { public function getDesc($params = []) {
if (empty($params)) if (empty($params))
return false; return false;
@ -280,6 +289,14 @@ class D2ItemDesc {
$par = $params['par']; $par = $params['par'];
$min = (int) $params['min']; $min = (int) $params['min'];
$v = $par; $v = $par;
// if ($params['dgrp']){
// $s1 = $params['gstring1'];
// $s2 = $params['gstring2'];
// $params['descfunc'] = $params['dgrpfunc'];
// $params['descval'] = $params['dgrpval'];
// }
if (empty($par)) { if (empty($par)) {
$v = $min; $v = $min;
@ -291,11 +308,13 @@ class D2ItemDesc {
$max = ''; $max = '';
} }
foreach ($this->skilltabs as $s) { if (empty($this->skilltabsDesc)){
$sql = "SELECT `String` FROM `strings` WHERE `Key`='$s'";
$this->skilltabsDesc[] = PDO_FetchRow($sql); foreach ($this->skilltabs as $s) {
$sql = "SELECT String FROM strings WHERE Key=?";
$this->skilltabsDesc[] = PDO_FetchRow($sql, [$s]);
}
} }
//ddump($this->skilltabsDescClean); //ddump($this->skilltabsDescClean);
/* /*