mirror of
https://gitlab.com/spaceti-app/integrations/acs/colnod-connector.git
synced 2026-07-12 16:50:48 +02:00
WIP: prepare data
This commit is contained in:
parent
3fbeb3130c
commit
0dea65a0b6
@ -131,8 +131,46 @@ bool SyncManager::startSynchronization()
|
|||||||
|
|
||||||
std::unique_ptr<PreparedData> SyncManager::prepareDataNew(const std::shared_ptr<Data> &databaseData, const std::shared_ptr<Data> &colnodData)
|
std::unique_ptr<PreparedData> SyncManager::prepareDataNew(const std::shared_ptr<Data> &databaseData, const std::shared_ptr<Data> &colnodData)
|
||||||
{
|
{
|
||||||
Q_UNUSED(databaseData);
|
auto preperedColnodData = std::make_shared<Data>();
|
||||||
Q_UNUSED(colnodData);
|
auto preperedDatabaseData = std::make_shared<Data>();
|
||||||
|
|
||||||
|
QList<QString> conflicts;
|
||||||
|
QList<QString> alreadySynced;
|
||||||
|
|
||||||
|
for (const auto &colnodToken : colnodData->updatedTokens) {
|
||||||
|
|
||||||
|
// not conflict so add to prepered tokens
|
||||||
|
if (!databaseData->updatedTokens.contains(colnodToken->id())) {
|
||||||
|
preperedColnodData->updatedTokens.insert(colnodToken->id(), colnodToken);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// change in colnod is newer
|
||||||
|
if (databaseData->updatedTokens.value(colnodToken->id()) < colnodToken) {
|
||||||
|
preperedColnodData->updatedTokens.insert(colnodToken->id(), colnodToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
// updated in db later
|
||||||
|
if (databaseData->updatedTokens.value(colnodToken->id()) > colnodToken) {
|
||||||
|
conflicts.append(colnodToken->id());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
auto token = database->getToken(colnodToken->id());
|
||||||
|
if ( token )
|
||||||
|
// alredy synced ( tokens are same )
|
||||||
|
if (token == colnodToken)
|
||||||
|
alreadySynced.append(colnodToken->id());
|
||||||
|
}
|
||||||
|
// remove tokens which should be not updated
|
||||||
|
for (const auto &id : conflicts)
|
||||||
|
colnodData->updatedTokens.remove(id);
|
||||||
|
for (const auto &id : alreadySynced)
|
||||||
|
colnodData->updatedTokens.remove(id);
|
||||||
|
|
||||||
|
qInfo(syncmanager) << tab << "-> COLNOD DATA - CHANGES:";
|
||||||
|
qInfo(syncmanager) << tab << tab << conflicts.size() << "TOKENS WERE ADDED/UPDATED IN DATABASE TOO";
|
||||||
|
qInfo(syncmanager) << tab << tab << alreadySynced.size() << "TOKENS WERE ALREADY SYNCED";
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user