From 472dd96716538ad64d8d347110f86e03be5687a7 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Fri, 29 May 2020 13:48:43 +0800 Subject: [PATCH] Cache country lookup result in PeerInfo class The country lookup happens quite often when "Resolve peer countries" option is enabled. --- src/base/bittorrent/peerinfo.cpp | 4 +++- src/base/bittorrent/peerinfo.h | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/base/bittorrent/peerinfo.cpp b/src/base/bittorrent/peerinfo.cpp index 21c13a0ff..5e07955e7 100644 --- a/src/base/bittorrent/peerinfo.cpp +++ b/src/base/bittorrent/peerinfo.cpp @@ -64,7 +64,9 @@ bool PeerInfo::fromLSD() const #ifndef DISABLE_COUNTRIES_RESOLUTION QString PeerInfo::country() const { - return Net::GeoIPManager::instance()->lookup(address().ip); + if (m_country.isEmpty()) + m_country = Net::GeoIPManager::instance()->lookup(address().ip); + return m_country; } #endif diff --git a/src/base/bittorrent/peerinfo.h b/src/base/bittorrent/peerinfo.h index 328cabf4c..251f161b2 100644 --- a/src/base/bittorrent/peerinfo.h +++ b/src/base/bittorrent/peerinfo.h @@ -102,6 +102,10 @@ namespace BitTorrent qreal m_relevance = 0; QString m_flags; QString m_flagsDescription; + +#ifndef DISABLE_COUNTRIES_RESOLUTION + mutable QString m_country; +#endif }; }