From f938cc04fea6841ffc73258b0545da4e011e0d18 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 27 Jan 2018 12:04:22 +0200 Subject: [PATCH] Instead of refresing with time call cache refresh only if missed. --HG-- branch : develop --- src/libs/ifc/xml/vdomdocument.cpp | 10 +++------- src/libs/ifc/xml/vdomdocument.h | 1 - 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/libs/ifc/xml/vdomdocument.cpp b/src/libs/ifc/xml/vdomdocument.cpp index ed488071d..66c899db5 100644 --- a/src/libs/ifc/xml/vdomdocument.cpp +++ b/src/libs/ifc/xml/vdomdocument.cpp @@ -197,15 +197,9 @@ VDomDocument::VDomDocument(QObject *parent) : QObject(parent), QDomDocument(), m_elementIdCache(), - m_refreshCacheTimer(new QTimer(this)), m_watcher(new QFutureWatcher>(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>::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(); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/ifc/xml/vdomdocument.h b/src/libs/ifc/xml/vdomdocument.h index d9de18f6c..cb490e116 100644 --- a/src/libs/ifc/xml/vdomdocument.h +++ b/src/libs/ifc/xml/vdomdocument.h @@ -150,7 +150,6 @@ private: Q_DISABLE_COPY(VDomDocument) /** @brief Map used for finding element by id. */ QHash m_elementIdCache; - QTimer *m_refreshCacheTimer; QFutureWatcher> *m_watcher; static bool find(QHash &cache, const QDomElement &node, quint32 id);