mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-16 02:03:07 -07:00
Faster GeoIP lookups.
QCache results in speed decrease. See https://github.com/qbittorrent/qBittorrent/pull/3488#issuecomment-124731983
This commit is contained in:
parent
ef5b3b90c3
commit
ad7ad8f596
2 changed files with 2 additions and 11 deletions
|
@ -57,7 +57,6 @@ GeoIPManager *GeoIPManager::m_instance = 0;
|
||||||
GeoIPManager::GeoIPManager()
|
GeoIPManager::GeoIPManager()
|
||||||
: m_enabled(false)
|
: m_enabled(false)
|
||||||
, m_geoIPDatabase(0)
|
, m_geoIPDatabase(0)
|
||||||
, m_cache(CACHE_SIZE)
|
|
||||||
{
|
{
|
||||||
configure();
|
configure();
|
||||||
connect(Preferences::instance(), SIGNAL(changed()), SLOT(configure()));
|
connect(Preferences::instance(), SIGNAL(changed()), SLOT(configure()));
|
||||||
|
@ -126,15 +125,8 @@ void GeoIPManager::downloadDatabaseFile()
|
||||||
|
|
||||||
QString GeoIPManager::lookup(const QHostAddress &hostAddr) const
|
QString GeoIPManager::lookup(const QHostAddress &hostAddr) const
|
||||||
{
|
{
|
||||||
if (m_enabled && m_geoIPDatabase) {
|
if (m_enabled && m_geoIPDatabase)
|
||||||
QString *country = m_cache.object(hostAddr);
|
return m_geoIPDatabase->lookup(hostAddr);
|
||||||
if (country)
|
|
||||||
return *country;
|
|
||||||
|
|
||||||
QString code = m_geoIPDatabase->lookup(hostAddr);
|
|
||||||
m_cache.insert(hostAddr, new QString(code));
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,7 +68,6 @@ namespace Net
|
||||||
|
|
||||||
bool m_enabled;
|
bool m_enabled;
|
||||||
GeoIPDatabase *m_geoIPDatabase;
|
GeoIPDatabase *m_geoIPDatabase;
|
||||||
mutable QCache<QHostAddress, QString> m_cache;
|
|
||||||
|
|
||||||
static GeoIPManager *m_instance;
|
static GeoIPManager *m_instance;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue