mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-09 18:08:39 +00:00
Only update the queue when necessary, not every second. This should
improve performance a bit.
This commit is contained in:
parent
bcd5b2c458
commit
e305e04e31
3 changed files with 37 additions and 29 deletions
|
@ -149,24 +149,15 @@ class Torrent:
|
||||||
if state not in TORRENT_STATE:
|
if state not in TORRENT_STATE:
|
||||||
log.debug("Trying to set an invalid state %s", state)
|
log.debug("Trying to set an invalid state %s", state)
|
||||||
return
|
return
|
||||||
|
|
||||||
# Only set 'Downloading' or 'Seeding' state if not paused
|
|
||||||
if state == "Downloading" or state == "Seeding":
|
|
||||||
# If we're Queued we need to resume the torrent first
|
|
||||||
if self.state != "Queued":
|
|
||||||
if self.handle.is_paused():
|
|
||||||
state = "Paused"
|
|
||||||
else:
|
|
||||||
return
|
|
||||||
|
|
||||||
if state == "Queued" and not self.handle.is_paused():
|
if state == "Queued" and not self.handle.is_paused():
|
||||||
component.get("TorrentManager").append_not_state_paused(self.torrent_id)
|
component.get("TorrentManager").append_not_state_paused(self.torrent_id)
|
||||||
self.handle.pause()
|
self.handle.pause()
|
||||||
|
|
||||||
if state == "Paused":
|
|
||||||
self.torrentqueue.update_order()
|
|
||||||
|
|
||||||
self.state = state
|
self.state = state
|
||||||
|
|
||||||
|
# Update the torrentqueue on any state changes
|
||||||
|
self.torrentqueue._update()
|
||||||
|
|
||||||
def get_eta(self):
|
def get_eta(self):
|
||||||
"""Returns the ETA in seconds for this torrent"""
|
"""Returns the ETA in seconds for this torrent"""
|
||||||
|
|
|
@ -611,7 +611,11 @@ class TorrentManager(component.Component):
|
||||||
# Get the torrent_id
|
# Get the torrent_id
|
||||||
torrent_id = str(alert.handle.info_hash())
|
torrent_id = str(alert.handle.info_hash())
|
||||||
# Set the torrent state
|
# Set the torrent state
|
||||||
self.torrents[torrent_id].set_state("Downloading")
|
if not self.torrents[torrent_id].handle.is_paused():
|
||||||
|
if self.torrents[torrent_id].handle.is_seed():
|
||||||
|
self.torrents[torrent_id].set_state("Seeding")
|
||||||
|
else:
|
||||||
|
self.torrents[torrent_id].set_state("Downloading")
|
||||||
|
|
||||||
def on_alert_tracker_reply(self, alert):
|
def on_alert_tracker_reply(self, alert):
|
||||||
log.debug("on_alert_tracker_reply")
|
log.debug("on_alert_tracker_reply")
|
||||||
|
|
|
@ -57,23 +57,26 @@ class TorrentQueue(component.Component):
|
||||||
self.config.register_set_function("max_active_downloading",
|
self.config.register_set_function("max_active_downloading",
|
||||||
self._on_set_max_active_downloading, False)
|
self._on_set_max_active_downloading, False)
|
||||||
|
|
||||||
def update(self):
|
def _update(self):
|
||||||
|
# Updates the queueing order and max active states
|
||||||
self.update_state_lists()
|
self.update_state_lists()
|
||||||
|
self.update_order()
|
||||||
self.update_max_active()
|
self.update_max_active()
|
||||||
|
|
||||||
def update_state_lists(self):
|
def update_state_lists(self):
|
||||||
|
# Get ordered lists of torrents
|
||||||
self.seeding = []
|
self.seeding = []
|
||||||
self.queued_seeding = []
|
self.queued_seeding = []
|
||||||
self.downloading = []
|
self.downloading = []
|
||||||
self.queued_downloading = []
|
self.queued_downloading = []
|
||||||
|
|
||||||
for torrent_id in self.torrents.get_torrent_list():
|
for torrent_id in self.torrents.get_torrent_list():
|
||||||
if self.torrents[torrent_id].get_status(["state"])["state"] == "Seeding":
|
if self.torrents[torrent_id].state == "Seeding":
|
||||||
self.seeding.append((self.queue.index(torrent_id), torrent_id))
|
self.seeding.append((self.queue.index(torrent_id), torrent_id))
|
||||||
elif self.torrents[torrent_id].get_status(["state"])["state"] == "Downloading":
|
elif self.torrents[torrent_id].state == "Downloading":
|
||||||
self.downloading.append((self.queue.index(torrent_id), torrent_id))
|
self.downloading.append((self.queue.index(torrent_id), torrent_id))
|
||||||
elif self.torrents[torrent_id].get_status(["state"])["state"] == "Queued":
|
elif self.torrents[torrent_id].state == "Queued":
|
||||||
if self.torrents[torrent_id].get_status(["is_seed"])["is_seed"]:
|
if self.torrents[torrent_id].handle.is_seed():
|
||||||
self.queued_seeding.append((self.queue.index(torrent_id), torrent_id))
|
self.queued_seeding.append((self.queue.index(torrent_id), torrent_id))
|
||||||
else:
|
else:
|
||||||
self.queued_downloading.append((self.queue.index(torrent_id), torrent_id))
|
self.queued_downloading.append((self.queue.index(torrent_id), torrent_id))
|
||||||
|
@ -90,7 +93,8 @@ class TorrentQueue(component.Component):
|
||||||
# log.debug("queued downloading: %s", len(self.queued_downloading))
|
# log.debug("queued downloading: %s", len(self.queued_downloading))
|
||||||
|
|
||||||
def update_order(self):
|
def update_order(self):
|
||||||
self.update_state_lists()
|
# This will queue/resume torrents if the queueing order changes
|
||||||
|
|
||||||
#try:
|
#try:
|
||||||
# log.debug("max(seeding): %s", max(self.seeding)[0])
|
# log.debug("max(seeding): %s", max(self.seeding)[0])
|
||||||
# log.debug("min(queued_seeding): %s", min(self.queued_seeding)[0])
|
# log.debug("min(queued_seeding): %s", min(self.queued_seeding)[0])
|
||||||
|
@ -106,7 +110,16 @@ class TorrentQueue(component.Component):
|
||||||
self.torrents[torrent_id].set_state("Queued")
|
self.torrents[torrent_id].set_state("Queued")
|
||||||
|
|
||||||
self.update_state_lists()
|
self.update_state_lists()
|
||||||
self.update_max_active()
|
|
||||||
|
if self.downloading != [] and self.queued_downloading != []:
|
||||||
|
if min(self.queued_downloading)[0] < max(self.downloading)[0]:
|
||||||
|
num_to_queue = max(self.downloading)[0] - min(self.queued_downloading)[0]
|
||||||
|
log.debug("queueing: %s", self.downloading[-num_to_queue:])
|
||||||
|
|
||||||
|
for (pos, torrent_id) in self.downloading[-num_to_queue:]:
|
||||||
|
self.torrents[torrent_id].set_state("Queued")
|
||||||
|
|
||||||
|
self.update_state_lists()
|
||||||
|
|
||||||
def update_max_active(self):
|
def update_max_active(self):
|
||||||
if self.config["max_active_seeding"] > -1:
|
if self.config["max_active_seeding"] > -1:
|
||||||
|
@ -226,7 +239,7 @@ class TorrentQueue(component.Component):
|
||||||
|
|
||||||
# Pop and insert the torrent_id at index - 1
|
# Pop and insert the torrent_id at index - 1
|
||||||
self.queue.insert(index - 1, self.queue.pop(index))
|
self.queue.insert(index - 1, self.queue.pop(index))
|
||||||
self.update_order()
|
self._update()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def top(self, torrent_id):
|
def top(self, torrent_id):
|
||||||
|
@ -244,7 +257,7 @@ class TorrentQueue(component.Component):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
self.queue.insert(0, self.queue.pop(index))
|
self.queue.insert(0, self.queue.pop(index))
|
||||||
self.update_order()
|
self._update()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def down(self, torrent_id):
|
def down(self, torrent_id):
|
||||||
|
@ -263,7 +276,7 @@ class TorrentQueue(component.Component):
|
||||||
|
|
||||||
# Pop and insert the torrent_id at index + 1
|
# Pop and insert the torrent_id at index + 1
|
||||||
self.queue.insert(index + 1, self.queue.pop(index))
|
self.queue.insert(index + 1, self.queue.pop(index))
|
||||||
self.update_order()
|
self._update()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def bottom(self, torrent_id):
|
def bottom(self, torrent_id):
|
||||||
|
@ -282,11 +295,11 @@ class TorrentQueue(component.Component):
|
||||||
|
|
||||||
# Pop and append the torrent_id
|
# Pop and append the torrent_id
|
||||||
self.append(self.queue.pop(index))
|
self.append(self.queue.pop(index))
|
||||||
self.update_order()
|
self._update()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def _on_set_max_active_seeding(self, key, value):
|
def _on_set_max_active_seeding(self, key, value):
|
||||||
self.update()
|
self._update()
|
||||||
|
|
||||||
def _on_set_max_active_downloading(self, key, value):
|
def _on_set_max_active_downloading(self, key, value):
|
||||||
self.update()
|
self._update()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue