Instead of refresing with time call cache refresh only if missed.
--HG-- branch : develop
This commit is contained in:
parent
ac94ef8a94
commit
f938cc04fe
|
@ -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();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------------
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue
Block a user