Optimize get_tracker_host by storing the tracker_host value
This commit is contained in:
parent
fa728510dd
commit
d1c47982a8
|
@ -1,7 +1,7 @@
|
|||
#
|
||||
# torrent.py
|
||||
#
|
||||
# Copyright (C) 2007, 2008 Andrew Resch <andrewresch@gmail.com>
|
||||
# Copyright (C) 2007-2009 Andrew Resch <andrewresch@gmail.com>
|
||||
#
|
||||
# Deluge is free software.
|
||||
#
|
||||
|
@ -31,8 +31,6 @@
|
|||
# this exception statement from your version. If you delete this exception
|
||||
# statement from all source files in the program, then also delete it here.
|
||||
#
|
||||
#
|
||||
|
||||
|
||||
"""Internal Torrent class"""
|
||||
|
||||
|
@ -166,6 +164,9 @@ class Torrent:
|
|||
# The tracker status
|
||||
self.tracker_status = ""
|
||||
|
||||
# This gets updated when get_tracker_host is called
|
||||
self.tracker_host = None
|
||||
|
||||
if state:
|
||||
self.time_added = state.time_added
|
||||
else:
|
||||
|
@ -293,6 +294,7 @@ class Torrent:
|
|||
tracker["tier"] = value.tier
|
||||
trackers.append(tracker)
|
||||
self.trackers = trackers
|
||||
self.tracker_host = None
|
||||
return
|
||||
|
||||
log.debug("Setting trackers for %s: %s", self.torrent_id, trackers)
|
||||
|
@ -314,6 +316,8 @@ class Torrent:
|
|||
# Force a reannounce if there is at least 1 tracker
|
||||
self.force_reannounce()
|
||||
|
||||
self.tracker_host = None
|
||||
|
||||
### End Options methods ###
|
||||
|
||||
def set_save_path(self, save_path):
|
||||
|
@ -494,6 +498,9 @@ class Torrent:
|
|||
def get_tracker_host(self):
|
||||
"""Returns just the hostname of the currently connected tracker
|
||||
if no tracker is connected, it uses the 1st tracker."""
|
||||
if self.tracker_host:
|
||||
return self.tracker_host
|
||||
|
||||
if not self.status:
|
||||
self.status = self.handle.status()
|
||||
|
||||
|
@ -521,6 +528,7 @@ class Torrent:
|
|||
host = ".".join(parts[-3:])
|
||||
else:
|
||||
host = ".".join(parts[-2:])
|
||||
self.tracker_host = host
|
||||
return host
|
||||
return ""
|
||||
|
||||
|
|
Loading…
Reference in New Issue