Module: deluge
Branch: last-seen-complete
Commit: 38906468c19d70fe022e7c4f560d693d53c0af47

Author: Pedro Algarvio <pe...@algarvio.me>
Date:   Sun May  8 01:36:40 2011 +0100

Last seen complete

Update last_seen_complete when a status is queried for and that key is on the 
keys to get or it's a full status query. Either way, only "calculate" last seen 
at a minimum of one time per 60 seconds(simple caching).

---

 deluge/core/torrent.py        |   20 +++++++++++++++-----
 deluge/core/torrentmanager.py |    3 ++-
 2 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/deluge/core/torrent.py b/deluge/core/torrent.py
index c21bf25..c94c833 100644
--- a/deluge/core/torrent.py
+++ b/deluge/core/torrent.py
@@ -564,6 +564,16 @@ class Torrent(object):
                 return host
         return ""
 
+    def get_last_seen_complete(self):
+        """
+        Returns the time a torrent was last seen complete, ie, with all pieces
+        available.
+        """
+        if lt.version_minor > 16:
+            return self.status.last_seen_complete
+        self.calculate_last_seen_complete()
+        return self._last_seen_complete
+
     def get_status(self, keys, diff=False):
         """
         Returns the status of the torrent based on the keys provided
@@ -639,10 +649,6 @@ class Torrent(object):
             "tracker_status": self.tracker_status,
             "upload_payload_rate": self.status.upload_payload_rate
         }
-        if lt.version_minor > 16:
-            full_status["last_seen_complete"] = self.status.last_seen_complete
-        else:
-            full_status["last_seen_complete"] = self._last_seen_complete
 
         def ti_comment():
             if self.handle.has_metadata():
@@ -715,6 +721,7 @@ class Torrent(object):
             "ratio": self.get_ratio,
             "total_size": ti_total_size,
             "tracker_host": self.get_tracker_host,
+            "last_seen_complete": self.get_last_seen_complete
         }
 
         # Create the desired status dictionary and return it
@@ -946,8 +953,11 @@ class Torrent(object):
             if not self.rpcserver.is_session_valid(key):
                 del self.prev_status[key]
 
-    # XXX: Remove when libtorrent 0.16 get's released???
     def calculate_last_seen_complete(self):
+        if self._last_seen_complete+60 > time.time():
+            # Simple caching. Only calculate every 1 min at minimum
+            return self._last_seen_complete
+
         availability = self.handle.piece_availability()
         if filter(lambda x: x<1, availability):
             # Torrent does not have all the pieces
diff --git a/deluge/core/torrentmanager.py b/deluge/core/torrentmanager.py
index 433f83f..1f49eb3 100644
--- a/deluge/core/torrentmanager.py
+++ b/deluge/core/torrentmanager.py
@@ -130,7 +130,8 @@ class TorrentManager(component.Component):
     """
 
     def __init__(self):
-        component.Component.__init__(self, "TorrentManager", interval=5, 
depend=["CorePluginManager"])
+        component.Component.__init__(self, "TorrentManager", interval=5,
+                                     depend=["CorePluginManager"])
         log.debug("TorrentManager init..")
         # Set the libtorrent session
         self.session = component.get("Core").session

-- 
You received this message because you are subscribed to the Google Groups 
"deluge-commit" group.
To post to this group, send email to deluge-commit@googlegroups.com.
To unsubscribe from this group, send email to 
deluge-commit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/deluge-commit?hl=en.

Reply via email to