Utility functions for entity flags and web data services

* multiple flags by name
* number of DB objects
* newer entities synchronized
This commit is contained in:
Klaus Basan
2018-04-02 02:24:08 +02:00
parent b6b37c9c0f
commit 574bc8b51b
4 changed files with 104 additions and 33 deletions

View File

@@ -456,6 +456,25 @@ namespace BlackCore
return emptyEntities;
}
CEntityFlags::Entity CWebDataServices::getSychronizedEntitiesWithNewerSharedFileOrEmpty(bool syncData, CEntityFlags::Entity entities)
{
CEntityFlags::Entity loadEntities = this->getEntitiesWithNewerSharedFile(entities);
const CEntityFlags::Entity checkForEmptyEntities = CEntityFlags::entityFlagToEntity(CEntityFlags::AllDbEntitiesNoInfoObjects) & ~loadEntities;
// it can happen the timestamps are not newer, but the data are empty
// - can happen if caches are copied and the TS does not represent the DB timestamp
// - cache files have been deleted
// - sync all DB entities
// - fast if there are no data
// - no impact if already synced
// - slow if newer synced before and all has to be done now
if (syncData) { this->synchronizeDbCaches(checkForEmptyEntities); }
// we have no newer timestamps, but incomplete data
loadEntities |= this->getEmptyEntities();
return loadEntities;
}
int CWebDataServices::getCacheCount(CEntityFlags::Entity entity) const
{
Q_ASSERT_X(CEntityFlags::isSingleEntity(entity), Q_FUNC_INFO, "Need single entity");
@@ -474,10 +493,24 @@ namespace BlackCore
int CWebDataServices::getDbInfoObjectCount(CEntityFlags::Entity entity) const
{
if (!m_dbInfoDataReader) return -1;
if (!m_dbInfoDataReader) { return -1; }
return this->getInfoObjectCount(entity, m_dbInfoDataReader);
}
int CWebDataServices::getDbInfoObjectsCount(CEntityFlags::Entity entities, bool stopIfNotFound) const
{
if (!m_dbInfoDataReader) { return -1; }
int total = 0;
CEntityFlags::EntitySet set = CEntityFlags::asSingleEntities(entities);
for (CEntityFlags::Entity single : set)
{
const int c = this->getDbInfoObjectCount(single);
if (c < 0 && stopIfNotFound) { return -1; }
if (c > 0) { total += c; }
}
return total;
}
int CWebDataServices::getSharedInfoObjectCount(CEntityFlags::Entity entity) const
{
if (!m_sharedInfoDataReader) return -1;

View File

@@ -416,6 +416,11 @@ namespace BlackCore
//! \threadsafe
BlackMisc::Network::CEntityFlags::Entity getEmptyEntities(BlackMisc::Network::CEntityFlags::Entity entities = BlackMisc::Network::CEntityFlags::AllDbEntities) const;
//! Synchronized entities either empty or with newer shared file
//! \remark will synchronize entities
//! \threadsafe
BlackMisc::Network::CEntityFlags::Entity getSychronizedEntitiesWithNewerSharedFileOrEmpty(bool syncData = true, BlackMisc::Network::CEntityFlags::Entity entities = BlackMisc::Network::CEntityFlags::AllDbEntities);
//! Cache count for entity
//! \threadsafe
int getCacheCount(BlackMisc::Network::CEntityFlags::Entity entity) const;
@@ -424,6 +429,10 @@ namespace BlackCore
//! \threadsafe
int getDbInfoObjectCount(BlackMisc::Network::CEntityFlags::Entity entity) const;
//! Count for 1-n entities from DB entity objects
//! \threadsafe
int getDbInfoObjectsCount(BlackMisc::Network::CEntityFlags::Entity entities, bool stopIfNotFound = true) const;
//! Count for entity from shared entity objects
//! \threadsafe
int getSharedInfoObjectCount(BlackMisc::Network::CEntityFlags::Entity entity) const;