Module: deluge
Branch: chunked-sessionproxy-and-gtkui-speedups
Commit: 89b79c76a32bea0def888c21211c2e8cdf412ce0

Author: Pedro Algarvio <[email protected]>
Date:   Sun May  8 22:08:39 2011 +0100

Multiple files prioritize first last.

Now `set_prioritize_first_last()` sets the first 2% and the last 2% of the 
pieces of each file on a torrent at a high priority, ie, it no longer works on 
just single file torrents.

---

 deluge/core/torrent.py |   28 ++++++++++++++++++++--------
 1 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/deluge/core/torrent.py b/deluge/core/torrent.py
index 26f3344..d9e9b7b 100644
--- a/deluge/core/torrent.py
+++ b/deluge/core/torrent.py
@@ -252,14 +252,26 @@ class Torrent(object):
 
     def set_prioritize_first_last(self, prioritize):
         self.options["prioritize_first_last_pieces"] = prioritize
-        if prioritize:
-            if self.handle.has_metadata():
-                if self.handle.get_torrent_info().num_files() == 1:
-                    # We only do this if one file is in the torrent
-                    priorities = [1] * 
self.handle.get_torrent_info().num_pieces()
-                    priorities[0] = 7
-                    priorities[-1] = 7
-                    self.handle.prioritize_pieces(priorities)
+        if self.handle.has_metadata():
+            if self.options["compact_allocation"]:
+                log.debug("Setting first/last priority with compact "
+                          "allocation does not work!")
+                return
+
+            paths = {}
+            ti = self.handle.get_torrent_info()
+            for n in range(ti.num_pieces()):
+                slices = ti.map_block(n, 0, ti.piece_size(n))
+                for slice in slices:
+                    fe = ti.file_at(slice.file_index)
+                    paths.setdefault(fe.path, []).append(n)
+
+            priorities = self.handle.piece_priorities()
+            for pieces in paths.itervalues():
+                two_percent = 2*100/len(pieces)
+                for piece in pieces[:two_percent]+pieces[-two_percent:]:
+                    priorities[piece] = prioritize and 7 or 1
+            self.handle.prioritize_pieces(priorities)
 
     def set_auto_managed(self, auto_managed):
         self.options["auto_managed"] = auto_managed

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

Reply via email to