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),
|
: QObject(parent),
|
||||||
QDomDocument(),
|
QDomDocument(),
|
||||||
m_elementIdCache(),
|
m_elementIdCache(),
|
||||||
m_refreshCacheTimer(new QTimer(this)),
|
|
||||||
m_watcher(new QFutureWatcher<QHash<quint32, QDomElement>>(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);
|
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);
|
m_elementIdCache.remove(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Cached missed
|
||||||
|
RefreshElementIdCache();
|
||||||
|
|
||||||
if (tagName.isEmpty())
|
if (tagName.isEmpty())
|
||||||
{
|
{
|
||||||
if (VDomDocument::find(m_elementIdCache, this->documentElement(), id))
|
if (VDomDocument::find(m_elementIdCache, this->documentElement(), id))
|
||||||
|
@ -621,7 +618,6 @@ void VDomDocument::RefreshElementIdCache()
|
||||||
void VDomDocument::CacheRefreshed()
|
void VDomDocument::CacheRefreshed()
|
||||||
{
|
{
|
||||||
m_elementIdCache = m_watcher->future().result();
|
m_elementIdCache = m_watcher->future().result();
|
||||||
m_refreshCacheTimer->start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
|
@ -150,7 +150,6 @@ private:
|
||||||
Q_DISABLE_COPY(VDomDocument)
|
Q_DISABLE_COPY(VDomDocument)
|
||||||
/** @brief Map used for finding element by id. */
|
/** @brief Map used for finding element by id. */
|
||||||
QHash<quint32, QDomElement> m_elementIdCache;
|
QHash<quint32, QDomElement> m_elementIdCache;
|
||||||
QTimer *m_refreshCacheTimer;
|
|
||||||
QFutureWatcher<QHash<quint32, QDomElement>> *m_watcher;
|
QFutureWatcher<QHash<quint32, QDomElement>> *m_watcher;
|
||||||
|
|
||||||
static bool find(QHash<quint32, QDomElement> &cache, const QDomElement &node, quint32 id);
|
static bool find(QHash<quint32, QDomElement> &cache, const QDomElement &node, quint32 id);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user