Browse Source

Create a seedtime table and a mysql trigger to update it

spaghetti 4 years ago
parent
commit
9615b4f903
2 changed files with 49 additions and 10 deletions
  1. 28
    0
      gazelle.sql
  2. 21
    10
      sections/snatchlist/snatchlist.php

+ 28
- 0
gazelle.sql View File

@@ -1600,6 +1600,16 @@ CREATE TABLE `users_push_notifications` (
1600 1600
   PRIMARY KEY (`UserID`)
1601 1601
 ) ENGINE=InnoDB CHARSET=utf8;
1602 1602
 
1603
+CREATE TABLE `users_seedtime` (
1604
+  `UserID` int(10) unsigned NOT NULL,
1605
+  `TorrentID` int(10) unsigned NOT NULL,
1606
+  `SeedTime` int(10) unsigned NOT NULL DEFAULT '0',
1607
+  `Uploaded` bigint(20) NOT NULL DEFAULT '0',
1608
+  `LastUpdate` datetime NOT NULL,
1609
+  `Downloaded` int(10) unsigned NOT NULL DEFAULT '0',
1610
+  PRIMARY KEY (`UserID`,`TorrentID`)
1611
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
1612
+
1603 1613
 CREATE TABLE `users_sessions` (
1604 1614
   `UserID` int(10) NOT NULL,
1605 1615
   `SessionID` char(64) NOT NULL,
@@ -1793,3 +1803,21 @@ INSERT INTO forums_categories (ID, Sort, Name) VALUES (10,10,'Help');
1793 1803
 INSERT INTO forums_categories (ID, Sort, Name) VALUES (8,8,'Music');
1794 1804
 
1795 1805
 INSERT INTO forums_categories (ID, Sort, Name) VALUES (20,20,'Trash');
1806
+
1807
+DELIMITER ;;
1808
+CREATE TRIGGER update_seedtime
1809
+  AFTER UPDATE ON `xbt_files_users`
1810
+  FOR EACH ROW BEGIN
1811
+    IF ( (OLD.timespent < NEW.timespent) AND (OLD.active = 1) AND (NEW.active = 1) ) THEN
1812
+      INSERT INTO users_seedtime
1813
+        (UserID, TorrentID, SeedTime, Uploaded, Downloaded, LastUpdate)
1814
+        VALUES
1815
+        (NEW.uid, NEW.fid, NEW.timespent, NEW.uploaded, NEW.downloaded, NOW())
1816
+        ON DUPLICATE KEY UPDATE
1817
+          SeedTime = SeedTime + (NEW.timespent - OLD.timespent),
1818
+          Uploaded = Uploaded + (NEW.uploaded - OLD.uploaded),
1819
+          Downloaded = Downloaded + (NEW.downloaded - OLD.downloaded),
1820
+          LastUpdate = NOW();
1821
+    END IF;
1822
+  END;;
1823
+DELIMITER ;

+ 21
- 10
sections/snatchlist/snatchlist.php View File

@@ -2,12 +2,22 @@
2 2
 $UserID = $LoggedUser['ID'];
3 3
 
4 4
 $DB->query("
5
-  SELECT g.ID,g.Name,g.WikiImage,g.CategoryID,x.fid,f.mtime,f.active,f.uploaded,f.downloaded,t.UserID,x.seedtime
6
-  FROM xbt_snatched as x
7
-  JOIN torrents AS t ON x.fid = t.ID
5
+  SELECT
6
+    g.ID,
7
+    g.Name,
8
+    g.WikiImage,
9
+    g.CategoryID,
10
+    f.active,
11
+    t.UserID,
12
+    s.TorrentID,
13
+    s.LastUpdate,
14
+    s.SeedTime,
15
+    s.Uploaded
16
+  FROM users_seedtime as s
17
+  JOIN torrents AS t ON s.TorrentID = t.ID
8 18
   JOIN torrents_group AS g ON g.ID = t.GroupID
9
-  LEFT JOIN xbt_files_users AS f ON x.fid = f.fid AND x.uid = f.uid
10
-  WHERE x.uid = $UserID");
19
+  LEFT JOIN xbt_files_users AS f ON s.TorrentID = f.fid AND s.UserID = f.uid
20
+  WHERE s.UserID = $UserID");
11 21
 if ($DB->has_results()) {
12 22
   $Torrents = $DB->to_array(false, MYSQLI_ASSOC, false);
13 23
 }
@@ -23,28 +33,29 @@ View::show_header('Snatch List');
23 33
     <tr class="colhead_dark">
24 34
       <td width="1%"></td>
25 35
       <td>Torrent</td>
36
+      <td class="number_column">Time Seeded</td>
26 37
       <td class="number_column">Last Active</td>
27 38
       <td class="number_column">HnR</td>
28 39
     </tr>
29 40
 <?
30 41
 foreach ($Torrents as $Torrent) {
31
-  $DisplayName = "<a href=\"torrents.php?id=$Torrent[ID]&torrentid=$Torrent[fid]\" ";
42
+  $DisplayName = "<a href=\"torrents.php?id=$Torrent[ID]&torrentid=$Torrent[TorrentID]\" ";
32 43
   if (!isset($LoggedUser['CoverArt']) || $LoggedUser['CoverArt']) {
33 44
     $DisplayName .= 'onmouseover="getCover(event)" data-cover="'.ImageTools::process($Torrent['WikiImage'], true).'" onmouseleave="ungetCover(event)" ';
34 45
   }
35 46
   $DisplayName .= "dir=\"ltr\">$Torrent[Name]</a>";
36 47
 
37 48
   $HnR = false;
38
-  if ($Torrent['seedtime'] < 48 &&
49
+  if ($Torrent['SeedTime'] < (2*24*60*60) &&
39 50
       $Torrent['active'] != "1" &&
40
-      $Torrent['UserID'] != $UserID &&
41
-      $Torrent['uploaded'] < $Torrent['downloaded']
51
+      $Torrent['UserID'] != $UserID
42 52
   ) $HnR = true;
43 53
 ?>
44 54
   <tr class="torrent">
45 55
     <td><div class="<?=Format::css_category($Torrent['CategoryID'])?>"></div></td>
46 56
     <td><a><?=$DisplayName ?></a></td>
47
-    <td class="number_column"><?=($Torrent['mtime']?date('Y-m-d H:i:s',$Torrent['mtime']):'Never') ?></td>
57
+    <td class="number_column"><?=time_diff(time()+$Torrent['SeedTime'], 2, false) ?></td>
58
+    <td class="number_column"><?=$Torrent['LastUpdate'] ?></td>
48 59
     <td class="number_column"><?=($HnR?'<a class="hnr-yes">Yes</a>':'<a class="hnr-no">No</a>') ?></td>
49 60
   </tr>
50 61
 <?

Loading…
Cancel
Save