@tmlmobilidade/utils 20260325.2343.38 → 20260326.219.51
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/batching/replicate.js +10 -12
- package/package.json +1 -1
|
@@ -51,9 +51,16 @@ export async function replicate({ countDestinationDbFn, countSourceDbFn, deleteD
|
|
|
51
51
|
const missingDocumentIds = sourceDbDocIds.filter((documentId) => !destinationDbDocIdsUnique.has(documentId));
|
|
52
52
|
const extraDocumentIds = destinationDbDocIds.filter(doc => !sourceDbDocIdsUnique.has(doc));
|
|
53
53
|
Logger.info(`Source Total: ${sourceDbCount} | Source Unique: ${sourceDbDocIdsUnique.size} | Source ▲: ${sourceDbCount - sourceDbDocIdsUnique.size} | Destination Total: ${destinationDbCount} | Destination Unique: ${destinationDbDocIdsUnique.size} | Destination ▲: ${destinationDbCount - destinationDbDocIdsUnique.size} | Destination Missing: ${missingDocumentIds.length} | Destination Extra: ${extraDocumentIds.length} (${distinctStepTimer.get()})`);
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
//
|
|
55
|
+
// If there are missing documents, then they are synced.
|
|
56
|
+
// We query the Source database for the missing documents
|
|
57
|
+
// and write them to the Destination database.
|
|
58
|
+
const missingStepTimer = new Timer();
|
|
59
|
+
if (missingDocumentIds.length > 0) {
|
|
60
|
+
for await (const sourceDbDocument of missingDocumentsSourceDbAsyncIterator(missingDocumentIds)) {
|
|
61
|
+
await writeSourceDocumentToDestinationDbFn(sourceDbDocument);
|
|
62
|
+
}
|
|
63
|
+
Logger.info(`Synced ${missingDocumentIds.length} missing documents to the Destination database. (${missingStepTimer.get()})`);
|
|
57
64
|
}
|
|
58
65
|
//
|
|
59
66
|
// Extra documents in the destination database should be removed,
|
|
@@ -64,15 +71,6 @@ export async function replicate({ countDestinationDbFn, countSourceDbFn, deleteD
|
|
|
64
71
|
Logger.info(`Deleted ${extraDocumentIds.length} extra documents in the Destination database. (${deleteStepTimer.get()})`);
|
|
65
72
|
}
|
|
66
73
|
//
|
|
67
|
-
// If there are missing documents, then they are synced.
|
|
68
|
-
// We query the Source database for the missing documents
|
|
69
|
-
// and write them to the Destination database.
|
|
70
|
-
const missingStepTimer = new Timer();
|
|
71
|
-
Logger.info(`Found ${missingDocumentIds.length} missing documents in the Destination database. (${missingStepTimer.get()})`);
|
|
72
|
-
for await (const sourceDbDocument of missingDocumentsSourceDbAsyncIterator(missingDocumentIds)) {
|
|
73
|
-
await writeSourceDocumentToDestinationDbFn(sourceDbDocument);
|
|
74
|
-
}
|
|
75
|
-
//
|
|
76
74
|
// After syncing the missing documents,
|
|
77
75
|
// run the onComplete callback function if provided.
|
|
78
76
|
if (onCompleteCallbackFn)
|