BioTorrents.de’s version of Gazelle
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

database_specifics.php 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <?php
  2. #declare(strict_types=1);
  3. $ENV = ENV::go();
  4. // View schemas
  5. if (!empty($_GET['table'])) {
  6. $DB->query('SHOW TABLES');
  7. $Tables =$DB->collect('Tables_in_'.$ENV->getPriv('SQLDB'));
  8. if (!in_array($_GET['table'], $Tables)) {
  9. error(0);
  10. }
  11. $DB->query('SHOW CREATE TABLE '.db_string($_GET['table']));
  12. list(, $Schema) = $DB->next_record(MYSQLI_NUM, false);
  13. header('Content-type: text/plain');
  14. error($Schema);
  15. }
  16. // Cache the tables for 4 hours, makes sorting faster
  17. if (!$Tables = $Cache->get_value('database_table_stats')) {
  18. $DB->query('SHOW TABLE STATUS');
  19. $Tables =$DB->to_array();
  20. $Cache->cache_value('database_table_stats', $Tables, 3600 * 4);
  21. }
  22. # todo: Remove Google Charts dependency
  23. require SERVER_ROOT.'/classes/charts.class.php';
  24. $Pie = new PIE_CHART(750, 400, array('Other'=>1,'Percentage'=>1,'Sort'=>1));
  25. // Begin sorting
  26. $Sort = [];
  27. switch (empty($_GET['order_by']) ? '' : $_GET['order_by']) {
  28. case 'name':
  29. foreach ($Tables as $Key => $Value) {
  30. $Pie->add($Value[0], $Value[6] + $Value[8]);
  31. $Sort[$Key] = $Value[0];
  32. }
  33. break;
  34. case 'engine':
  35. foreach ($Tables as $Key => $Value) {
  36. $Pie->add($Value[0], $Value[6] + $Value[8]);
  37. $Sort[$Key] = $Value[1];
  38. }
  39. break;
  40. case 'rows':
  41. foreach ($Tables as $Key => $Value) {
  42. $Pie->add($Value[0], $Value[4]);
  43. $Sort[$Key] = $Value[4];
  44. }
  45. break;
  46. case 'rowsize':
  47. foreach ($Tables as $Key => $Value) {
  48. $Pie->add($Value[0], $Value[5]);
  49. $Sort[$Key] = $Value[5];
  50. }
  51. break;
  52. case 'datasize':
  53. foreach ($Tables as $Key => $Value) {
  54. $Pie->add($Value[0], $Value[6]);
  55. $Sort[$Key] = $Value[6];
  56. }
  57. break;
  58. case 'indexsize':
  59. foreach ($Tables as $Key => $Value) {
  60. $Pie->add($Value[0], $Value[8]);
  61. $Sort[$Key] = $Value[8];
  62. }
  63. break;
  64. case 'totalsize':
  65. default:
  66. foreach ($Tables as $Key => $Value) {
  67. $Pie->add($Value[0], $Value[6] + $Value[8]);
  68. $Sort[$Key] = $Value[6] + $Value[8];
  69. }
  70. }
  71. $Pie->generate();
  72. if (!empty($_GET['order_way']) && $_GET['order_way'] === 'asc') {
  73. $SortWay = SORT_ASC;
  74. } else {
  75. $SortWay = SORT_DESC;
  76. }
  77. array_multisort($Sort, $SortWay, $Tables);
  78. // End sorting
  79. ?>
  80. <h3>Database</h3>
  81. <div class="box pad center">
  82. <img src="<?=$Pie->url()?>" />
  83. </div>
  84. <br />
  85. <?php
  86. # Staff Only: Detailed schema info / table dumps
  87. if (check_perms('site_debug')) { ?>
  88. <h3>Specifics</h3>
  89. <div class="box pad center">
  90. <table>
  91. <tr class="colhead">
  92. <td>
  93. <a
  94. href="stats.php?action=torrents&order_by=name&order_way=<?=(!empty($_GET['order_by']) && $_GET['order_by'] === 'name' && !empty($_GET['order_way']) && $_GET['order_way'] === 'desc') ? 'asc' : 'desc'?>">Name</a>
  95. </td>
  96. <td>
  97. <a
  98. href="stats.php?action=torrents&order_by=engine&order_way=<?=(!empty($_GET['order_by']) && $_GET['order_by'] === 'engine' && !empty($_GET['order_way']) && $_GET['order_way'] === 'desc') ? 'asc' : 'desc'?>">Engine</a>
  99. </td>
  100. <td>
  101. <a
  102. href="stats.php?action=torrents&order_by=rows&order_way=<?=(!empty($_GET['order_by']) && $_GET['order_by'] === 'rows' && !empty($_GET['order_way']) && $_GET['order_way'] === 'desc') ? 'asc' : 'desc'?>">Rows
  103. </td>
  104. <td>
  105. <a
  106. href="stats.php?action=torrents&order_by=rowsize&order_way=<?=(!empty($_GET['order_by']) && $_GET['order_by'] === 'rowsize' && !empty($_GET['order_way']) && $_GET['order_way'] === 'desc') ? 'asc' : 'desc'?>">Row
  107. Size</a>
  108. </td>
  109. <td>
  110. <a
  111. href="stats.php?action=torrents&order_by=datasize&order_way=<?=(!empty($_GET['order_by']) && $_GET['order_by'] === 'datasize' && !empty($_GET['order_way']) && $_GET['order_way'] === 'desc') ? 'asc' : 'desc'?>">Data
  112. Size</a>
  113. </td>
  114. <td>
  115. <a
  116. href="stats.php?action=torrents&order_by=indexsize&order_way=<?=(!empty($_GET['order_by']) && $_GET['order_by'] === 'indexsize' && !empty($_GET['order_way']) && $_GET['order_way'] === 'desc') ? 'asc' : 'desc'?>">Index
  117. Size</a>
  118. </td>
  119. <td>
  120. <a
  121. href="stats.php?action=torrents&order_by=totalsize&order_way=<?=(!empty($_GET['order_by']) && $_GET['order_by'] === 'totalsize' && !empty($_GET['order_way']) && $_GET['order_way'] === 'desc') ? 'asc' : 'desc'?>">Total
  122. Size
  123. </td>
  124. <td>
  125. Tools
  126. </td>
  127. </tr>
  128. <?php
  129. $TotalRows = 0;
  130. $TotalDataSize = 0;
  131. $TotalIndexSize = 0;
  132. foreach ($Tables as $Table) {
  133. list($Name, $Engine, , , $Rows, $RowSize, $DataSize, , $IndexSize) = $Table;
  134. $TotalRows += $Rows;
  135. $TotalDataSize += $DataSize;
  136. $TotalIndexSize += $IndexSize; ?>
  137. <tr class="row">
  138. <td>
  139. <?=display_str($Name)?>
  140. </td>
  141. <td>
  142. <?=display_str($Engine)?>
  143. </td>
  144. <td>
  145. <?=number_format($Rows)?>
  146. </td>
  147. <td>
  148. <?=Format::get_size($RowSize)?>
  149. </td>
  150. <td>
  151. <?=Format::get_size($DataSize)?>
  152. </td>
  153. <td>
  154. <?=Format::get_size($IndexSize)?>
  155. </td>
  156. <td>
  157. <?=Format::get_size($DataSize + $IndexSize)?>
  158. </td>
  159. <td>
  160. <a href="tools.php?action=database_specifics&table=<?=display_str($Name)?>"
  161. class="brackets">Schema</a>
  162. </td>
  163. </tr>
  164. <?php
  165. }
  166. ?>
  167. <tr>
  168. <td></td>
  169. <td></td>
  170. <td>
  171. <?=number_format($TotalRows)?>
  172. </td>
  173. <td></td>
  174. <td>
  175. <?=Format::get_size($TotalDataSize)?>
  176. </td>
  177. <td>
  178. <?=Format::get_size($TotalIndexSize)?>
  179. </td>
  180. <td>
  181. <?=Format::get_size($TotalDataSize + $TotalIndexSize)?>
  182. </td>
  183. <td></td>
  184. </tr>
  185. </table>
  186. </div>
  187. <?php
  188. } # end if check_perms()