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.

stats.php 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <?php
  2. declare(strict_types=1);
  3. // Begin user stats
  4. if (($UserCount = $Cache->get_value('stats_user_count')) === false) {
  5. $DB->query("
  6. SELECT
  7. COUNT(`ID`)
  8. FROM
  9. `users_main`
  10. WHERE
  11. `Enabled` = '1'
  12. ");
  13. list($UserCount) = $DB->next_record();
  14. $Cache->cache_value('stats_user_count', $UserCount, 0); // inf cache
  15. }
  16. if (($UserStats = $Cache->get_value('stats_users')) === false) {
  17. $DB->query("
  18. SELECT
  19. COUNT(`ID`)
  20. FROM
  21. `users_main`
  22. WHERE
  23. `Enabled` = '1'
  24. AND `LastAccess` > '".time_minus(3600 * 24)."'
  25. ");
  26. list($UserStats['Day']) = $DB->next_record();
  27. $DB->query("
  28. SELECT
  29. COUNT(`ID`)
  30. FROM
  31. `users_main`
  32. WHERE
  33. `Enabled` = '1'
  34. AND `LastAccess` > '".time_minus(3600 * 24 * 7)."'
  35. ");
  36. list($UserStats['Week']) = $DB->next_record();
  37. $DB->query("
  38. SELECT
  39. COUNT(`ID`)
  40. FROM
  41. `users_main`
  42. WHERE
  43. `Enabled` = '1'
  44. AND LastAccess > '".time_minus(3600 * 24 * 30)."'
  45. ");
  46. list($UserStats['Month']) = $DB->next_record();
  47. $Cache->cache_value('stats_users', $UserStats, 0);
  48. }
  49. // Begin torrent stats
  50. if (($TorrentCount = $Cache->get_value('stats_torrent_count')) === false) {
  51. $DB->query("
  52. SELECT
  53. COUNT(`ID`)
  54. FROM
  55. `torrents`
  56. ");
  57. list($TorrentCount) = $DB->next_record();
  58. $Cache->cache_value('stats_torrent_count', $TorrentCount, 604800); // staggered 1 week cache
  59. }
  60. if (($AlbumCount = $Cache->get_value('stats_album_count')) === false) {
  61. $DB->query("
  62. SELECT
  63. COUNT(`id`)
  64. FROM
  65. `torrents_group`
  66. WHERE
  67. `category_id` = '1'
  68. ");
  69. list($AlbumCount) = $DB->next_record();
  70. $Cache->cache_value('stats_album_count', $AlbumCount, 604830); // staggered 1 week cache
  71. }
  72. if (($ArtistCount = $Cache->get_value('stats_artist_count')) === false) {
  73. $DB->query("
  74. SELECT
  75. COUNT(`ArtistID`)
  76. FROM
  77. `artists_group`
  78. ");
  79. list($ArtistCount) = $DB->next_record();
  80. $Cache->cache_value('stats_artist_count', $ArtistCount, 604860); // staggered 1 week cache
  81. }
  82. // Begin request stats
  83. if (($RequestStats = $Cache->get_value('stats_requests')) === false) {
  84. $DB->query("
  85. SELECT
  86. COUNT(`ID`)
  87. FROM
  88. `requests`
  89. ");
  90. list($RequestCount) = $DB->next_record();
  91. $DB->query("
  92. SELECT
  93. COUNT(`ID`)
  94. FROM
  95. `requests`
  96. WHERE
  97. `FillerID` > 0
  98. ");
  99. list($FilledCount) = $DB->next_record();
  100. $Cache->cache_value('stats_requests', array($RequestCount, $FilledCount), 11280);
  101. } else {
  102. list($RequestCount, $FilledCount) = $RequestStats;
  103. }
  104. // Begin swarm stats
  105. if (($PeerStats = $Cache->get_value('stats_peers')) === false) {
  106. // Cache lock!
  107. if ($Cache->get_query_lock('peer_stats')) {
  108. $DB->query("
  109. SELECT
  110. IF(
  111. `remaining` = 0,
  112. 'Seeding',
  113. 'Leeching'
  114. ) AS `Type`,
  115. COUNT(`uid`)
  116. FROM
  117. `xbt_files_users`
  118. WHERE
  119. `active` = 1
  120. GROUP BY
  121. `Type`
  122. ");
  123. $PeerCount = $DB->to_array(0, MYSQLI_NUM, false);
  124. $LeecherCount = isset($PeerCount['Leeching']) ? $PeerCount['Leeching'][1] : 0;
  125. $SeederCount = isset($PeerCount['Seeding']) ? $PeerCount['Seeding'][1] : 0;
  126. $Cache->cache_value('stats_peers', array($LeecherCount, $SeederCount), 1209600); // 2 week cache
  127. $Cache->clear_query_lock('peer_stats');
  128. } else {
  129. $LeecherCount = $SeederCount = 0;
  130. }
  131. } else {
  132. list($LeecherCount, $SeederCount) = $PeerStats;
  133. }
  134. json_print('success', array(
  135. 'maxUsers' => USER_LIMIT,
  136. 'enabledUsers' => (int) $UserCount,
  137. 'usersActiveThisDay' => (int) $UserStats['Day'],
  138. 'usersActiveThisWeek' => (int) $UserStats['Week'],
  139. 'usersActiveThisMonth' => (int) $UserStats['Month'],
  140. 'torrentCount' => (int) $TorrentCount,
  141. 'groupCount' => (int) $AlbumCount,
  142. 'artistCount' => (int) $ArtistCount,
  143. 'requestCount' => (int) $RequestCount,
  144. 'filledRequestCount' => (int) $FilledCount,
  145. 'seederCount' => (int) $SeederCount,
  146. 'leecherCount' => (int) $LeecherCount
  147. ));