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

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