Instead of refresing with time call cache refresh only if missed.

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2018-01-27 12:04:22 +02:00
parent ac94ef8a94
commit f938cc04fe
2 changed files with 3 additions and 8 deletions

View File

@ -197,15 +197,9 @@ VDomDocument::VDomDocument(QObject *parent)
: QObject(parent),
QDomDocument(),
m_elementIdCache(),
m_refreshCacheTimer(new QTimer(this)),
m_watcher(new QFutureWatcher<QHash<quint32, QDomElement>>(this))
{
m_refreshCacheTimer->setTimerType(Qt::VeryCoarseTimer);
m_refreshCacheTimer->setInterval(10000);
m_refreshCacheTimer->setSingleShot(true);
connect(m_refreshCacheTimer, &QTimer::timeout, this, &VDomDocument::RefreshElementIdCache);
connect(m_watcher, &QFutureWatcher<QHash<quint32, QDomElement>>::finished, this, &VDomDocument::CacheRefreshed);
m_refreshCacheTimer->start();
}
//---------------------------------------------------------------------------------------------------------------------
@ -226,6 +220,9 @@ QDomElement VDomDocument::elementById(quint32 id, const QString &tagName)
m_elementIdCache.remove(id);
}
// Cached missed
RefreshElementIdCache();
if (tagName.isEmpty())
{
if (VDomDocument::find(m_elementIdCache, this->documentElement(), id))
@ -621,7 +618,6 @@ void VDomDocument::RefreshElementIdCache()
void VDomDocument::CacheRefreshed()
{
m_elementIdCache = m_watcher->future().result();
m_refreshCacheTimer->start();
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -150,7 +150,6 @@ private:
Q_DISABLE_COPY(VDomDocument)
/** @brief Map used for finding element by id. */
QHash<quint32, QDomElement> m_elementIdCache;
QTimer *m_refreshCacheTimer;
QFutureWatcher<QHash<quint32, QDomElement>> *m_watcher;
static bool find(QHash<quint32, QDomElement> &cache, const QDomElement &node, quint32 id);