mirror of
https://github.com/mumble-voip/mumble.git
synced 2025-10-26 11:19:16 +00:00
Cache pingsort
This commit is contained in:
parent
3b234512f9
commit
146cc63a15
@ -59,6 +59,7 @@ void PingStats::init() {
|
||||
uiMaxUsers = 0;
|
||||
uiBandwidth = 0;
|
||||
uiSent = 0;
|
||||
uiRecv = 0;
|
||||
uiVersion = 0;
|
||||
}
|
||||
|
||||
@ -423,7 +424,6 @@ QVariant ServerItem::data(int column, int role) const {
|
||||
qsl << qha.toString();
|
||||
|
||||
double ploss = 100.0;
|
||||
quint32 uiRecv = static_cast<quint32>(boost::accumulators::count(* asQuantile));
|
||||
|
||||
if (uiSent > 0)
|
||||
ploss = (uiSent - qMin(uiRecv, uiSent)) * 100. / uiSent;
|
||||
@ -506,14 +506,18 @@ void ServerItem::setDatas(double elapsed, quint32 users, quint32 maxusers) {
|
||||
dPing = elapsed;
|
||||
|
||||
quint32 ping = static_cast<quint32>(lround(dPing / 1000.));
|
||||
uiRecv = static_cast<quint32>(boost::accumulators::count(* asQuantile));
|
||||
|
||||
bool changed = (ping != uiPing) || (users != uiUsers) || (maxusers != uiMaxUsers);
|
||||
|
||||
uiUsers = users;
|
||||
uiMaxUsers = maxusers;
|
||||
uiPing = ping;
|
||||
|
||||
if ((uiPingSort == 0) || (dPing < (950. * uiPingSort)) || (dPing > (1050. * uiPingSort)))
|
||||
|
||||
double grace = qMax(5000., 50. * uiPingSort);
|
||||
double diff = fabs(1000. * uiPingSort - dPing);
|
||||
|
||||
if ((uiPingSort == 0) || ((uiSent >= 10) && (diff >= grace)))
|
||||
uiPingSort = ping;
|
||||
|
||||
if (changed)
|
||||
@ -783,20 +787,26 @@ ConnectDialog::ConnectDialog(QWidget *p) : QDialog(p) {
|
||||
|
||||
qtwServers->setCurrentItem(NULL);
|
||||
bLastFound = false;
|
||||
|
||||
|
||||
qmPingCache = Database::getPingCache();
|
||||
}
|
||||
|
||||
ConnectDialog::~ConnectDialog() {
|
||||
ServerItem::qmIcons.clear();
|
||||
|
||||
QList<FavoriteServer> ql;
|
||||
qmPingCache.clear();
|
||||
|
||||
foreach(ServerItem *si, qlItems) {
|
||||
if (si->uiPing)
|
||||
qmPingCache.insert(QPair<QString, unsigned short>(si->qsHostname, si->usPort), si->uiPing);
|
||||
|
||||
if (si->itType != ServerItem::FavoriteType)
|
||||
continue;
|
||||
ql << si->toFavoriteServer();
|
||||
}
|
||||
Database::setFavorites(ql);
|
||||
Database::setPingCache(qmPingCache);
|
||||
}
|
||||
|
||||
void ConnectDialog::accept() {
|
||||
@ -1342,6 +1352,9 @@ void ConnectDialog::udpReply() {
|
||||
quint32 users = qFromBigEndian(ping[3]);
|
||||
quint32 maxusers = qFromBigEndian(ping[4]);
|
||||
si->uiBandwidth = qFromBigEndian(ping[5]);
|
||||
|
||||
if (! si->uiPingSort)
|
||||
si->uiPingSort = qmPingCache.value(QPair<QString, unsigned short>(si->qsHostname, si->usPort));
|
||||
|
||||
si->setDatas(static_cast<double>(elapsed), users, maxusers);
|
||||
si->hideCheck();
|
||||
|
||||
@ -66,6 +66,7 @@ public:
|
||||
quint32 uiMaxUsers;
|
||||
quint32 uiBandwidth;
|
||||
quint32 uiSent;
|
||||
quint32 uiRecv;
|
||||
|
||||
double dPing;
|
||||
|
||||
@ -132,7 +133,6 @@ class ServerItem : public QTreeWidgetItem, public PingStats {
|
||||
|
||||
QString qsUrl;
|
||||
|
||||
|
||||
QString qsBonjourHost;
|
||||
BonjourRecord brRecord;
|
||||
|
||||
@ -210,6 +210,8 @@ class ConnectDialog : public QDialog, public Ui::ConnectDialog {
|
||||
|
||||
QHash<qpAddress, quint64> qhPingRand;
|
||||
QHash<qpAddress, QSet<ServerItem *> > qhPings;
|
||||
|
||||
QMap<QPair<QString, unsigned short>, unsigned int> qmPingCache;
|
||||
|
||||
bool bIPv4;
|
||||
bool bIPv6;
|
||||
|
||||
@ -112,6 +112,9 @@ Database::Database() {
|
||||
query.exec(QLatin1String("CREATE TABLE IF NOT EXISTS `muted` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `hash` TEXT)"));
|
||||
query.exec(QLatin1String("CREATE UNIQUE INDEX IF NOT EXISTS `muted_hash` ON `muted`(`hash`)"));
|
||||
|
||||
query.exec(QLatin1String("CREATE TABLE IF NOT EXISTS `pingcache` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `hostname` TEXT, `port` INTEGER, `ping` INTEGER)"));
|
||||
query.exec(QLatin1String("CREATE UNIQUE INDEX IF NOT EXISTS `pingcache_host_port` ON `pingcache`(`hostname`,`port`)"));
|
||||
|
||||
query.exec(QLatin1String("DELETE FROM `comments` WHERE `seen` < datetime('now', '-1 years')"));
|
||||
}
|
||||
|
||||
@ -178,6 +181,38 @@ void Database::setLocalMuted(const QString &hash, bool muted) {
|
||||
query.exec();
|
||||
}
|
||||
|
||||
QMap<QPair<QString, unsigned short>, unsigned int> Database::getPingCache() {
|
||||
QSqlQuery query;
|
||||
QMap<QPair<QString, unsigned short>, unsigned int> map;
|
||||
|
||||
query.prepare(QLatin1String("SELECT `hostname`, `port`, `ping` FROM `pingcache`"));
|
||||
query.exec();
|
||||
while (query.next()) {
|
||||
map.insert(QPair<QString, unsigned short>(query.value(0).toString(), query.value(1).toUInt()), query.value(2).toUInt());
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
void Database::setPingCache(const QMap<QPair<QString, unsigned short>, unsigned int> &map) {
|
||||
QSqlQuery query;
|
||||
QMap<QPair<QString, unsigned short>, unsigned int>::const_iterator i;
|
||||
|
||||
QSqlDatabase::database().transaction();
|
||||
|
||||
query.prepare(QLatin1String("DELETE FROM `pingcache`"));
|
||||
query.exec();
|
||||
|
||||
query.prepare(QLatin1String("REPLACE INTO `pingcache` (`hostname`, `port`, `ping`) VALUES (?,?,?)"));
|
||||
for(i = map.constBegin(); i != map.constEnd(); ++i) {
|
||||
query.addBindValue(i.key().first);
|
||||
query.addBindValue(i.key().second);
|
||||
query.addBindValue(i.value());
|
||||
query.exec();
|
||||
}
|
||||
|
||||
QSqlDatabase::database().commit();
|
||||
}
|
||||
|
||||
bool Database::seenComment(const QString &hash, const QString &comment) {
|
||||
QSqlQuery query;
|
||||
|
||||
|
||||
@ -56,6 +56,9 @@ class Database : public QObject {
|
||||
|
||||
static bool isLocalMuted(const QString &hash);
|
||||
static void setLocalMuted(const QString &hash, bool muted);
|
||||
|
||||
static QMap<QPair<QString, unsigned short>, unsigned int> getPingCache();
|
||||
static void setPingCache(const QMap<QPair<QString, unsigned short>, unsigned int> &cache);
|
||||
|
||||
static bool seenComment(const QString &hash, const QString &comment);
|
||||
static void setSeenComment(const QString &hash, const QString &comment);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user