From 0c7d65b8b5707bf01ee89cea04525250235a1b9c Mon Sep 17 00:00:00 2001 From: Sandip Pandey Date: Tue, 12 Jun 2018 14:18:28 +0200 Subject: [PATCH] fixed bug with updating torrent --- Tribler/community/popular/repository.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/Tribler/community/popular/repository.py b/Tribler/community/popular/repository.py index ba544816c58..64fc3354208 100644 --- a/Tribler/community/popular/repository.py +++ b/Tribler/community/popular/repository.py @@ -44,6 +44,12 @@ def get_top_torrents(self, limit=DEFAULT_TORRENT_LIMIT): def update_torrent_health(self, torrent_health_payload, peer_trust=0): assert torrent_health_payload and isinstance(torrent_health_payload, TorrentHealthPayload) + def update_torrent(db_handler, health_payload): + db_handler.updateTorrent(infohash, notify=False, num_seeders=health_payload.num_seeders, + num_leechers=health_payload.num_leechers, + last_tracker_check=int(health_payload.timestamp), + status=u"good" if health_payload.num_seeders > 1 else u"unknown") + if not self.torrent_db: self._logger.error("Torrent DB is None") return @@ -52,14 +58,13 @@ def update_torrent_health(self, torrent_health_payload, peer_trust=0): if self.has_torrent(infohash): db_torrent = self.get_torrent(infohash) is_fresh = time.time() - db_torrent['last_tracker_check'] < DEFAULT_FRESHNESS_LIMIT - if is_fresh or peer_trust < 2: - self._logger.info("Database record is either fresh or peer trust score is too low. Ignoring response.") + if is_fresh and peer_trust < 2: + self._logger.info("Database record is already fresh and the sending peer trust " + "score is too low so we just ignore the response.") return # Update the torrent health anyway. A torrent info request should be sent separately to request additional info. - self.update_torrent_in_db(self, infohash, seeder=torrent_health_payload.num_seeders, - leecher=torrent_health_payload.num_leechers, - last_torrent_check=int(torrent_health_payload.timestamp)) + update_torrent(self.torrent_db, torrent_health_payload) def update_torrent_info(self, torrent_info_response): infohash = torrent_info_response.infohash @@ -70,7 +75,7 @@ def update_torrent_info(self, torrent_info_response): return # Update local database - self.update_torrent_in_db(self, infohash, name=torrent_info_response.name, + self.torrent_db.updateTorrent(infohash, notify=False, name=torrent_info_response.name, length=torrent_info_response.length, creation_date=torrent_info_response.creation_date, num_files=torrent_info_response.num_files, @@ -82,7 +87,4 @@ def get_torrent(self, infohash): return self.torrent_db.getTorrent(infohash, keys=keys, include_mypref=False) def has_torrent(self, infohash): - return self.torrent_db.hasTorrent(infohash) - - def update_torrent_in_db(self, infohash, **kw): - self.torrent_db.updateTorrent(infohash, notify=False, **kw) + return self.get_torrent(infohash) is not None