Ref T237, find latest DB cache ts and only init caches if there are no or old cache data

This commit is contained in:
Klaus Basan
2018-01-30 23:31:25 +01:00
parent fd6bfdb7c0
commit 0101e31db2
4 changed files with 32 additions and 4 deletions

View File

@@ -865,11 +865,18 @@ namespace BlackCore
m_webDataServices.reset( m_webDataServices.reset(
new CWebDataServices(m_webReadersUsed, m_dbReaderConfig, {}, this) new CWebDataServices(m_webReadersUsed, m_dbReaderConfig, {}, this)
); );
Q_ASSERT_X(m_webDataServices, Q_FUNC_INFO, "Missing web services");
// caches from local files (i.e. the files delivered) // caches from local files (i.e. the files delivered)
if (this->isInstallerOptionSet()) if (this->isInstallerOptionSet())
{ {
msgs.push_back(m_webDataServices->initDbCachesFromLocalResourceFiles(false)); const QDateTime ts = m_webDataServices->getLatestDbEntityCacheTimestamp();
if (!ts.isValid() || ts < QDateTime::currentDateTimeUtc().addYears(-2))
{
// we only init, if there are:
// a) no cache timestamps b) or it was not updated for some years
msgs.push_back(m_webDataServices->initDbCachesFromLocalResourceFiles(false));
}
} }
// watchdog // watchdog

View File

@@ -262,7 +262,7 @@ namespace BlackCore
//! Delegates to QCommandLineParser::isSet //! Delegates to QCommandLineParser::isSet
bool isParserOptionSet(const QString &option) const; bool isParserOptionSet(const QString &option) const;
//! Installer called? //! Called by installer?
bool isInstallerOptionSet() const; bool isInstallerOptionSet() const;
//! Delegates to QCommandLineParser::isSet //! Delegates to QCommandLineParser::isSet

View File

@@ -419,6 +419,22 @@ namespace BlackCore
return reader->getLatestEntityTimestampFromSharedInfoObjects(entity); return reader->getLatestEntityTimestampFromSharedInfoObjects(entity);
} }
QDateTime CWebDataServices::getLatestDbEntityCacheTimestamp() const
{
QDateTime latest;
const CEntityFlags::EntitySet set = CEntityFlags::asSingleEntities(CEntityFlags::AllDbEntitiesNoInfoObjects);
for (CEntityFlags::Entity e : set)
{
const QDateTime ts = this->getCacheTimestamp(e);
if (!ts.isValid()) { continue; }
if (!latest.isValid() || latest < ts)
{
latest = ts;
}
}
return latest;
}
CEntityFlags::Entity CWebDataServices::getEntitiesWithNewerSharedFile(CEntityFlags::Entity entities) const CEntityFlags::Entity CWebDataServices::getEntitiesWithNewerSharedFile(CEntityFlags::Entity entities) const
{ {
Q_ASSERT_X(m_sharedInfoDataReader, Q_FUNC_INFO, "Shared info reader was not initialized"); Q_ASSERT_X(m_sharedInfoDataReader, Q_FUNC_INFO, "Shared info reader was not initialized");

View File

@@ -77,8 +77,7 @@ namespace BlackCore
/*! /*!
* Encapsulates reading data from web sources * Encapsulates reading data from web sources
*/ */
class BLACKCORE_EXPORT CWebDataServices : class BLACKCORE_EXPORT CWebDataServices : public QObject
public QObject
{ {
Q_OBJECT Q_OBJECT
@@ -385,11 +384,17 @@ namespace BlackCore
//! \threadsafe //! \threadsafe
QDateTime getCacheTimestamp(BlackMisc::Network::CEntityFlags::Entity entity) const; QDateTime getCacheTimestamp(BlackMisc::Network::CEntityFlags::Entity entity) const;
//! Latest DB object timestamp, or null if there is no such timestamp
//! \threadsafe
QDateTime getLatestDbEntityCacheTimestamp() const;
//! Corresponding DB timestamp if applicable //! Corresponding DB timestamp if applicable
//! \remark from Db::CInfoDataReader
//! \threadsafe //! \threadsafe
QDateTime getLatestDbEntityTimestamp(BlackMisc::Network::CEntityFlags::Entity entity) const; QDateTime getLatestDbEntityTimestamp(BlackMisc::Network::CEntityFlags::Entity entity) const;
//! Shared info object timestamp //! Shared info object timestamp
//! \remark from Db::CInfoDataReader
//! \threadsafe //! \threadsafe
QDateTime getLatestSharedInfoObjectTimestamp(BlackMisc::Network::CEntityFlags::Entity entity) const; QDateTime getLatestSharedInfoObjectTimestamp(BlackMisc::Network::CEntityFlags::Entity entity) const;