From c7e6f79a07ac74a7c4cccca1daaa48f506668627 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Fri, 27 Jul 2018 01:11:34 +0200 Subject: [PATCH] Ref T292, Ref T285 avoid unnecessary calls of cache synchronize in DB readers Rational: Normally calling synchronize multiple times does not matter. However, it can time out if the cache is in use (e.g. saving) and create an exception. This exception is just unwanted "noise". --- src/blackcore/db/airportdatareader.cpp | 2 +- src/blackcore/db/airportdatareader.h | 5 ++++- src/blackcore/db/icaodatareader.cpp | 6 +++--- src/blackcore/db/icaodatareader.h | 4 ++++ src/blackcore/db/modeldatareader.cpp | 6 +++--- src/blackcore/db/modeldatareader.h | 3 +++ 6 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/blackcore/db/airportdatareader.cpp b/src/blackcore/db/airportdatareader.cpp index 899b947ca..72da6315a 100644 --- a/src/blackcore/db/airportdatareader.cpp +++ b/src/blackcore/db/airportdatareader.cpp @@ -152,7 +152,7 @@ namespace BlackCore void CAirportDataReader::synchronizeCaches(CEntityFlags::Entity entities) { - if (entities.testFlag(CEntityFlags::AirportEntity)) { m_airportCache.synchronize(); } + if (entities.testFlag(CEntityFlags::AirportEntity)) { if (m_syncedAirportCache) { return; } m_syncedAirportCache = true; m_airportCache.synchronize(); } } void CAirportDataReader::admitCaches(CEntityFlags::Entity entities) diff --git a/src/blackcore/db/airportdatareader.h b/src/blackcore/db/airportdatareader.h index ce62edce8..775ad0e65 100644 --- a/src/blackcore/db/airportdatareader.h +++ b/src/blackcore/db/airportdatareader.h @@ -17,7 +17,9 @@ #include "blackcore/db/databasereader.h" #include "blackmisc/aviation/airportlist.h" #include "blackmisc/network/entityflags.h" + #include +#include namespace BlackCore { @@ -73,7 +75,8 @@ namespace BlackCore BlackMisc::Db::CDbFlags::DataRetrievalModeFlag mode = BlackMisc::Db::CDbFlags::DbReading, const QDateTime &newerThan = QDateTime()); private: - BlackMisc::CData m_airportCache {this, &CAirportDataReader::airportCacheChanged}; + BlackMisc::CData m_airportCache {this, &CAirportDataReader::airportCacheChanged}; //!< cache file + std::atomic_bool m_syncedAirportCache { false }; //!< already synchronized? //! Reader URL (we read from where?) used to detect changes of location BlackMisc::CData m_readerUrlCache {this, &CAirportDataReader::baseUrlCacheChanged }; diff --git a/src/blackcore/db/icaodatareader.cpp b/src/blackcore/db/icaodatareader.cpp index b0c7bb9dd..5bb244942 100644 --- a/src/blackcore/db/icaodatareader.cpp +++ b/src/blackcore/db/icaodatareader.cpp @@ -576,9 +576,9 @@ namespace BlackCore void CIcaoDataReader::synchronizeCaches(CEntityFlags::Entity entities) { - if (entities.testFlag(CEntityFlags::AircraftIcaoEntity)) { m_aircraftIcaoCache.synchronize(); } - if (entities.testFlag(CEntityFlags::AirlineIcaoEntity)) { m_airlineIcaoCache.synchronize(); } - if (entities.testFlag(CEntityFlags::CountryEntity)) { m_countryCache.synchronize(); } + if (entities.testFlag(CEntityFlags::AircraftIcaoEntity)) { if (m_syncedAircraftIcaoCache) { return; } m_syncedAircraftIcaoCache = true; m_aircraftIcaoCache.synchronize(); } + if (entities.testFlag(CEntityFlags::AirlineIcaoEntity)) { if (m_syncedAirlineIcaoCache) { return; } m_syncedAirlineIcaoCache = true; m_airlineIcaoCache.synchronize(); } + if (entities.testFlag(CEntityFlags::CountryEntity)) { if (m_syncedCountryCache) { return; } m_syncedCountryCache = true; m_countryCache.synchronize(); } } void CIcaoDataReader::admitCaches(CEntityFlags::Entity entities) diff --git a/src/blackcore/db/icaodatareader.h b/src/blackcore/db/icaodatareader.h index 969be511b..43c7cee56 100644 --- a/src/blackcore/db/icaodatareader.h +++ b/src/blackcore/db/icaodatareader.h @@ -26,6 +26,7 @@ #include #include #include +#include class QDateTime; class QNetworkReply; @@ -162,6 +163,9 @@ namespace BlackCore BlackMisc::CData m_aircraftIcaoCache {this, &CIcaoDataReader::aircraftIcaoCacheChanged }; BlackMisc::CData m_airlineIcaoCache {this, &CIcaoDataReader::airlineIcaoCacheChanged }; BlackMisc::CData m_countryCache {this, &CIcaoDataReader::countryCacheChanged }; + std::atomic_bool m_syncedAircraftIcaoCache { false }; //!< already synchronized? + std::atomic_bool m_syncedAirlineIcaoCache { false }; //!< already synchronized? + std::atomic_bool m_syncedCountryCache { false }; //!< already synchronized? //! Reader URL (we read from where?) used to detect changes of location BlackMisc::CData m_readerUrlCache {this, &CIcaoDataReader::baseUrlCacheChanged }; diff --git a/src/blackcore/db/modeldatareader.cpp b/src/blackcore/db/modeldatareader.cpp index 0507b1341..c0a10adcf 100644 --- a/src/blackcore/db/modeldatareader.cpp +++ b/src/blackcore/db/modeldatareader.cpp @@ -579,9 +579,9 @@ namespace BlackCore void CModelDataReader::synchronizeCaches(CEntityFlags::Entity entities) { - if (entities.testFlag(CEntityFlags::LiveryEntity)) { m_liveryCache.synchronize(); } - if (entities.testFlag(CEntityFlags::ModelEntity)) { m_modelCache.synchronize(); } - if (entities.testFlag(CEntityFlags::DistributorEntity)) { m_distributorCache.synchronize(); } + if (entities.testFlag(CEntityFlags::LiveryEntity)) { if (m_syncedLiveryCache) { return; } m_syncedLiveryCache = true; m_liveryCache.synchronize(); } + if (entities.testFlag(CEntityFlags::ModelEntity)) { if (m_syncedModelCache) { return; } m_syncedModelCache = true; m_modelCache.synchronize(); } + if (entities.testFlag(CEntityFlags::DistributorEntity)) { if (m_syncedDistributorCache) { return; } m_syncedDistributorCache = true; m_distributorCache.synchronize(); } } void CModelDataReader::admitCaches(CEntityFlags::Entity entities) diff --git a/src/blackcore/db/modeldatareader.h b/src/blackcore/db/modeldatareader.h index 3067c0c51..fb5be60cd 100644 --- a/src/blackcore/db/modeldatareader.h +++ b/src/blackcore/db/modeldatareader.h @@ -165,6 +165,9 @@ namespace BlackCore BlackMisc::CData m_liveryCache { this, &CModelDataReader::liveryCacheChanged }; BlackMisc::CData m_modelCache { this, &CModelDataReader::modelCacheChanged }; BlackMisc::CData m_distributorCache { this, &CModelDataReader::distributorCacheChanged }; + std::atomic_bool m_syncedLiveryCache { false }; //!< already synchronized? + std::atomic_bool m_syncedModelCache { false }; //!< already synchronized? + std::atomic_bool m_syncedDistributorCache { false }; //!< already synchronized? //! Reader URL (we read from where?) used to detect changes of location BlackMisc::CData m_readerUrlCache { this, &CModelDataReader::baseUrlCacheChanged };