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.

record_seeding.php 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. #declare(strict_types=1);
  3. // Record who's seeding how much, used for ratio watch
  4. $DB->query("TRUNCATE TABLE users_torrent_history_temp");
  5. // Find seeders that have announced within the last hour
  6. $DB->query("
  7. INSERT INTO users_torrent_history_temp
  8. (UserID, NumTorrents)
  9. SELECT uid, COUNT(DISTINCT fid)
  10. FROM xbt_files_users
  11. WHERE mtime > unix_timestamp(NOW() - INTERVAL 1 HOUR)
  12. AND Remaining = 0
  13. GROUP BY uid");
  14. // Mark new records as "checked" and set the current time as the time
  15. // the user started seeding <NumTorrents> seeded.
  16. // Finished = 1 means that the user hasn't been seeding exactly <NumTorrents> earlier today.
  17. // This query will only do something if the next one inserted new rows last hour.
  18. $DB->query("
  19. UPDATE users_torrent_history AS h
  20. JOIN users_torrent_history_temp AS t ON t.UserID = h.UserID
  21. AND t.NumTorrents = h.NumTorrents
  22. SET h.Finished = '0',
  23. h.LastTime = UNIX_TIMESTAMP(NOW())
  24. WHERE h.Finished = '1'
  25. AND h.Date = UTC_DATE() + 0");
  26. // Insert new rows for users who haven't been seeding exactly <NumTorrents> torrents earlier today
  27. // and update the time spent seeding <NumTorrents> torrents for the others.
  28. // Primary table index: (UserID, NumTorrents, Date).
  29. $DB->query("
  30. INSERT INTO users_torrent_history
  31. (UserID, NumTorrents, Date)
  32. SELECT UserID, NumTorrents, UTC_DATE() + 0
  33. FROM users_torrent_history_temp
  34. ON DUPLICATE KEY UPDATE
  35. Time = Time + UNIX_TIMESTAMP(NOW()) - LastTime,
  36. LastTime = UNIX_TIMESTAMP(NOW())");