Optimize get_tracker_host by storing the tracker_host value

This commit is contained in:
Andrew Resch 2009-05-28 19:16:58 +00:00
parent fa728510dd
commit d1c47982a8
1 changed files with 14 additions and 6 deletions

View File

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